Archive for July, 2013

Converting UNIX time to/from ISO 8601 format

Sunday, July 21st, 2013

In PHP, To convert from epoch to iso time:

   $timestamp = 1374421626;
   echo date('Y-m-d H:i:s', $timestamp);

In PHP, And to convert from iso to epoch time:

   $isodate = "2013-07-21 22:23:24";
   echo strtotime($isodate);

In Java, while using system default Locale and TimeZone:

String epochToIso8601(long time) {
    String format = "yyyy-MM-dd HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
    return sdf.format(new Date(time * 1000));

Just have not yet needed the reverse function yet.

/** TODO: insert code here */