Get current date and time stamp of ISO8601

I would like to receive the current date / time stamp of the server or client in the ISO8601 format (for example, December 31, 2009, 02:53). I know that server time can be observed using PHP and contributed to the DOM using jQuery $ .getJson. Client time can be recorded in the browser using javascript / jQuery. I want the timestamp to be static (not dynamic / in real time). Im php / JS newbie and really appreciate your help. Thanks.

+4
source share
2 answers

For JavaScript, just create a new Date object like this

 var currentDate = new Date(); 

and then you can create the date in any format using the methods that Date provides. See this link for a complete list of methods you can use.

In your case, you can do something like this:

 var months = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); var currentDate = new Date(); var formatedDate = currentDate.getDate() + ' ' + months[currentDate.getMonth()] + ' ' + currentDate.getFullYear() + ' ' + currentDate.getHours() + ':' + currentDate.getMinutes(); 

As for PHP, it's simple:

 $formatedDate = date("c"); 

See this page for a full reference to the Date() function.

+7
source

In PHP 5 you can do

 date("c"); // ISO 8601 date (added in PHP 5) 

see date

+15
source

All Articles