Get current ISO8601 date/time stamp

I would like to get the current date/time stamp of the server or client in ISO8601 format (ex. 31 Dec 2009, 02:53). I know that server time can be observed using PHP and brought into the DOM using jQuery $.getJson. Client side time can be recorded from the browser using javascript/jQuery. I want the time stamp to be static (not dynamic/real-time). Im php/JS newbie and would greatly appreciate your help. Thanks.

  • How do I get the current time only in JavaScript
  • date.setHours() not working
  • Convert time to 24 hours format in Javascript
  • What is the best way to parse a time into a Date object from user input in Javascript?
  • datepicker parsing date issue
  • Strange bug with date calculation
  • How to convert time milliseconds to hours, min, sec format in JavaScript?
  • JavaScript clock based on TimeAPI
  • How Do I Create A Countdown Time That Resets At A Specific Time
  • How to check if current time falls within a specific range on a week day using jquery/javascript?
  • Firebase new Date()?
  • How to get the day of week and the month of the year?
  • 2 Solutions collect form web for “Get current ISO8601 date/time stamp”

    For JavaScript just create a new Date object like this

    var currentDate = new Date();

    and then you can construct your date in any format you want using the methods that Date provides. See this reference for the complete list of methods you can use.

    In your case you could 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 as simple as this:

    $formatedDate = date("c");

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

    In PHP 5, you can do

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

    see date