Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

JavaScript: Change Format of Date and Time from String

Using JavaScript, I want to convert this:
12/30/2012 1:07:10 PM

Into this:
December 30, 2012 at 1:07:10 pm
Avatar of leakim971
leakim971
Flag of Guadeloupe image

test page : http://jsfiddle.net/zdzS6/

function changeFormat(IM_A_STRING) {
     var d = new Date(IM_A_STRING);
     return ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","December"][d.getMonth(d)] + " " + d.getDate() + ", " + d.getFullYear() + " at " + IM_A_STRING.split(/^[^\s]*\s/).pop().toLowerCase();
}

Open in new window

Avatar of hankknight

ASKER

Thanks, but could you hide the milliseconds?

For example:
3:35 pm
Instead of:
3:35:43 pm
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial