0

I'm wondering if there is anything like this?

I'm getting my CMS to sort the content by date, so this is my approach.

First getting the current time.

var date = Date.now();

It will return me 1374426602321.

So now when I want to display that to the user and obviously we don't want to display the above, so I'm using this right now.

var formattedDate = new Date(date).toDateString(),

That will output

Sun Jul 21 2013

Which is good, but that is not really the correct or perfect way I guess.

I'm expecting more like Sunday July 21, 2013.

Is there a way that we can accomplish this by not using any of the plugin or any module and not having to create like another function to format this??

This is being done in the server-side using Node.js

Ali
  • 9,997
  • 20
  • 70
  • 105
  • There are plenty of questions on Date formatting. See http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript – user568109 Jul 21 '13 at 18:33

1 Answers1

1

use a library or a function... don't see any other way.

function getDateString(d){
   return 
   ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][d.getDay()]+" "+ 
   ["January","February","March","April","May","June","July","August","September","October","November","December"][d.getMonth()]+" "+ 
   d.getDate()+", "+
   d.getFullYear();
}
gp.
  • 8,074
  • 3
  • 38
  • 39