0

I am having a little difficulty with this.How can I display a date value to format 10 September 2014 using Javascript.

What I am doing at the moment is

var dateAdded = new Date(parseInt(user.DateAdded.substr(6)));

which gives me Wed Sep 10 2014

Arianule
  • 8,811
  • 45
  • 116
  • 174
  • The [Date API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) provides methods for getting different parts of a date. – Pointy Sep 12 '14 at 12:43
  • 1
    if you don't mind using a library I always go for http://momentjs.com/ when doing things with dates in js gives so may options for things like this including languages. – Quince Sep 12 '14 at 12:47

1 Answers1

1

duplicate of How to format a JavaScript date

but Marko's accepted answer there for you:

Taken from http://www.webdevelopersnotes.com/tips/html/javascript_date_and_time.php3:

<script type="text/javascript">
<!--

var m_names = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");

var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
document.write(curr_date + "-" + m_names[curr_month] 
+ "-" + curr_year);

//-->
</script>

You can edit the array to use Jan, Feb, Mar, etc..

Community
  • 1
  • 1