Format date value to string in ISO 8601 "yyyy-MM-dd'T'HH:mm:ssz" FORMAT - Android java.util

Android examples for java.util:Date Format

Description

Format date value to string in ISO 8601 "yyyy-MM-dd'T'HH:mm:ssz" FORMAT

Demo Code

import android.util.Log;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{
    private static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz";
    /**/*from www  . j a  va 2s  . c om*/
     * Format a Date into ISO 8601 Complaint format.
     * @return date string, or empty string if input was null
     */
    public static String getIso8601String(Date d) {
        SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_FORMAT);
        String result = "";
        if (d != null) {
            result = sdf.format(d);
        }
        return result;
    }

}

Related Tutorials