date To Iso String in yyyy-MM-dd'T'HH:mm:ssZ format - Android java.util

Android examples for java.util:Date Format

Description

date To Iso String in yyyy-MM-dd'T'HH:mm:ssZ format

Demo Code

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**//from w  w  w .ja va2s. c o  m
     * dateToIso8601String
     *   Date to Iso8601 String
     *   2011-09-24T19:45:31+02:00
     * @param date
     * @return String
     */
    public static String dateToIso8601String(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(
                "yyyy-MM-dd'T'HH:mm:ssZ");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        return sdf.format(date);
    }

}

Related Tutorials