Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import android.text.TextUtils; public class Main { public static String getFormattedDate() { return getFormattedDate(System.currentTimeMillis()); } public static String getFormattedDate(long millis) { String resp = ""; try { resp = getFormattedDate(new Date(millis)); } catch (Exception ex) { } return resp; } public static String getFormattedDate(Date date) { String resp = ""; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US); resp = sdf.format(date); } catch (Exception ex) { } return resp; } public static String getFormattedDate(Long millis, String timeZone) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US); if (!TextUtils.isEmpty(timeZone)) sdf.setTimeZone(TimeZone.getTimeZone(timeZone)); return millis != null ? sdf.format(new Date(millis)) : ""; } }