chiprivers Posted October 7, 2010 Share Posted October 7, 2010 In my current application, I am working with dates in the format 'YYYY-MM-DD HH:MM:SS'. The main reason I am using this format is because it is the format stored in my MYSQL database. I have had no problems working with this format in the PHP elements of my script, however I need some assistance with the javascript! I need to be able to output a datetime string in the above format from my javascript date object. In PHP it woudld be simple, $date->format('Y-m-d H:i:s'); but from what I can see with Javascript, you have to extract each portion of the date and time. This wouldn't be such a problem if the numbers for months and days were prefixed with 0s where applicable! Is there a straight forward function for this that I have missed somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/215377-format-output-of-javascript-date-object/ Share on other sites More sharing options...
KevinM1 Posted October 7, 2010 Share Posted October 7, 2010 Just pass in a date string to a Date's constructor. If your date format is YYYY-MM-DD HH:MM:SS, replace the punctuation with commas (see the bottom of this page for an example: https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date). Quote Link to comment https://forums.phpfreaks.com/topic/215377-format-output-of-javascript-date-object/#findComment-1120023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.