Java 日期和时间转换Class SimpleDateFormat

原创
2015/09/02 14:16
阅读数 456
Date and Time Pattern Result
"yyyy.MM.dd G 'at' HH:mm:ss z" 2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy" Wed, Jul 4, '01
"h:mm a" 12:08 PM
"hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time
"K:mm a, z" 0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa" 02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z" Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ" 010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" 2001-07-04T12:08:56.235-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX" 2001-07-04T12:08:56.235-07:00
"YYYY-'W'ww-u" 2001-W27-3


private static Locale en_SG=new Locale("en", "SG");
public static final SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd",
en_SG);
public static final SimpleDateFormat sdf2 = new SimpleDateFormat("dd MMM yyyy",
en_SG);
public static final SimpleDateFormat sdf3 = new SimpleDateFormat("dd/MM/yyyy HH:mm",
en_SG);
public static final SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS",
en_SG);
public static final SimpleDateFormat sdf5 = new SimpleDateFormat("EEE, dd MMM yyyy",
en_SG);
public static final SimpleDateFormat sdf6 = new SimpleDateFormat("hh:mm aa",
en_SG);
public static final SimpleDateFormat sdf7 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
en_SG);
public static final SimpleDateFormat sdf8 = new SimpleDateFormat("EEEEEEEEE, hh:mm aa",
en_SG);
public static final SimpleDateFormat sdf9 = new SimpleDateFormat("HH",
en_SG);
public static final SimpleDateFormat sdf10 = new SimpleDateFormat("hh:mm",
en_SG);
public static final SimpleDateFormat sdf11= new SimpleDateFormat("yyyyMMdd",
en_SG);
public static final SimpleDateFormat sdf12 = new SimpleDateFormat("aa",en_SG);

public static final SimpleDateFormat sdf13 = new SimpleDateFormat("HH:mm",en_SG);
public static final SimpleDateFormat sdf14 = new SimpleDateFormat("EE d MMM yyyy",
en_SG);
public static final SimpleDateFormat sdf15 = new SimpleDateFormat("yyyy-MM-dd HH:mm aaa",
en_SG);

//for utc time transfer to SG local time use:
public static final SimpleDateFormat sdf4_UTC = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS",
Locale.ENGLISH);
public static final SimpleDateFormat sdf7_UTC = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
Locale.ENGLISH);
public static final SimpleDateFormat sdf13_UTC = new SimpleDateFormat("HH:mm",
Locale.ENGLISH);
public static int TIME_OFFSET=0;
static{
sdf4_UTC.setTimeZone(TimeZone.getTimeZone("Europe/London"));
sdf7_UTC.setTimeZone(TimeZone.getTimeZone("Europe/London"));
sdf13_UTC.setTimeZone(TimeZone.getTimeZone("Europe/London"));
TimeZone gmt = TimeZone.getTimeZone("Europe/London");
Calendar gmtCal = Calendar.getInstance(gmt);
TIME_OFFSET = gmtCal.get(Calendar.DST_OFFSET);
Log.d("gyy", "TIME_OFFSET "+TIME_OFFSET);
}

String datedisplay=Constants.sdf5.format(Constants.sdf4.parse(medals.get(position).getMedalUpdateTime()));


展开阅读全文
打赏
0
5 收藏
分享
加载中
更多评论
打赏
0 评论
5 收藏
0
分享
返回顶部
顶部