slinden77 slinden77 - 10 months ago 115
Java Question

Changing unix timestamp to ISO8601 timestamp

I need to convert a unix timestamp (millis) to ISO8601.
A solution with JodaTime is fine, I can't figure it out.

EDIT: I am using this as per the accepted solution:

public static String getISO8601StringFromMillis(long millis){
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
return dateFormat.format(new Date(millis));


Try following.

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class TestDate {
    public static void main(String[] args) {

    public static String getDate(long timestamp) {
        TimeZone timezone = TimeZone.getTimeZone("UTC");
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
        String isoStr = dateFormat.format(new Date(timestamp));

        return isoStr;