0

Super noob to JavaScript. Would like to create a DateObject, but am still stuck.

Wondering how I can convert a date from toDateString to custom 'MMM DD'.

Tue Mar 09 2014 > Mar 09

*basically, need to parse out the day of the week and the year.

I would like to add any additional objects and functions to this(already converting from UTC):

 function dateChange(date) {
return date.toDateString();
}

Thanks in advance; looking forward to learning where I am going wrong.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
  • possible duplicate of [Where can I find documentation on formatting a date in JavaScript](http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Matt Johnson-Pint Mar 09 '15 at 01:59

1 Answers1

0

You could use substr(), although it only makes sense if you're consistently using that same date format.

Or, you could use split():

var splitString = date.toDateString().split(" ");
return splitString[1]+" "+splitString[2];

If you want a more flexible library, check out Datejs (specificially, the FormatSpecifiers would be useful).

Noah B
  • 331
  • 1
  • 9