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
https://forums.phpfreaks.com/topic/243026-parse-utc-string/
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
https://forums.phpfreaks.com/topic/243026-parse-utc-string/#findComment-1248638
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.