Jump to content

format output of javascript date object


chiprivers

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/215377-format-output-of-javascript-date-object/
Share on other sites

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).

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.