Jump to content

Parse UTC string?


dfowler

Recommended Posts

Hey guys, I am needing to display the date of when an article was created on my site.  I have a UTC string (and this is all I will ever have).  So I added this to my page:

var d = new Date();
d.setTime(createdDate *1000);

Where createdDate is a UTC value like "1266870137".

 

The problem is the out put from that looks somthing like this: Mon Feb 22 2010 15:22:17 GMT-0500 (Eastern Standard Time).  I'm hoping to only end up with something like this: February 22, 2010

 

I would appreciate any help.  I've spent quite a while googling and looking at w3schools.  I'm just fried at this point.  Thanks!

Link to comment
Share on other sites

try this

var d = new Date(createdDate *1000);
alert(d.toDateString());

 

That is pretty close, still has the day of the week in there and an abbreviated month.  I will play around a bit though.  Thanks for the starting point!

Link to comment
Share on other sites

Here is what I ended up having to do:

    var theDate = new Date();
    theDate.setTime(createdDate  * 1000);
    var year  = theDate.getUTCFullYear(); 
    var month = theDate.getUTCMonth();
    var day = theDate.getUTCDate();
    var d = months[month] + " " + day + ", " + year;

I created an array with the month names in it since getUTCMonth only returns a number.  However, it works and gives me the output I need.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.