Java tutorial
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { /** * RFC 3339 date format for UTC dates. */ public static final String RFC3339UTC = "yyyy-MM-dd'T'HH:mm:ss'Z'"; /** * RFC 3339 date format for localtime dates with offset. */ public static final String RFC3339LOCAL = "yyyy-MM-dd'T'HH:mm:ssZ"; private static ThreadLocal<SimpleDateFormat> RFC3339Formatter = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat(RFC3339UTC, Locale.US); } }; public static String formatRFC3339Local(Date date) { SimpleDateFormat format = RFC3339Formatter.get(); format.applyPattern(RFC3339LOCAL); String result = format.format(date); format.applyPattern(RFC3339UTC); return result; } }