dfowler Posted July 27, 2011 Share Posted July 27, 2011 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 More sharing options...
gristoi Posted July 28, 2011 Share Posted July 28, 2011 try this var d = new Date(createdDate *1000); alert(d.toDateString()); Link to comment https://forums.phpfreaks.com/topic/243026-parse-utc-string/#findComment-1248406 Share on other sites More sharing options...
dfowler Posted July 28, 2011 Author Share Posted July 28, 2011 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 https://forums.phpfreaks.com/topic/243026-parse-utc-string/#findComment-1248540 Share on other sites More sharing options...
dfowler Posted July 28, 2011 Author Share Posted July 28, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.