Here you can find the source of parse(String time, String df)
Parameter | Description |
---|---|
time | a parameter |
df | a parameter |
public static Date parse(String time, String df)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static final String DEFAULT_FORMAT = "EEE MMM dd HH:mm:ss z yyyy"; /**//from w w w . j av a 2 s.c o m * Parse to GMT date * @param time * @param df * @return */ public static Date parse(String time, SimpleDateFormat df) { return parse(time, df, null); } public static Date parse(String time, SimpleDateFormat df, TimeZone timeZone) { try { Date date = df.parse(time); if (timeZone != null) { date = fromLocalTZ(date, timeZone); } return date; } catch (ParseException e) { return null; } } /** * Parse to GMT date * @param time * @param df * @return */ public static Date parse(String time, String df) { return parse(time, df, null); } public static Date parse(String time, String df, TimeZone timeZone) { try { Date date = new SimpleDateFormat(df).parse(time); if (timeZone != null) { date = fromLocalTZ(date, timeZone); } return date; } catch (ParseException e) { return null; } } public static Date parse(String time, String[] dfs, TimeZone timeZone) { for (String df : dfs) { Date parse = parse(time, df, timeZone); if (parse != null) { return parse; } } return null; } public static Date parse(String dateStr) { return parse(dateStr, DEFAULT_FORMAT); } public static Date fromLocalTZ(Date time, TimeZone localTimeZone) { return new Date(time.getTime() - (localTimeZone.getRawOffset() - TimeZone.getDefault().getRawOffset())); } }