List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:Main.java
public static long parseTimeToLong(String time) { if (null == time) return System.currentTimeMillis(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); java.util.Date d;// www .j a v a2 s . com try { d = sdf.parse(time); return d.getTime(); } catch (Exception e) { e.printStackTrace(); } return System.currentTimeMillis(); }
From source file:Main.java
public static java.util.Calendar getCalendarFromStringDate(String dateString) { java.util.Calendar calendar = java.util.Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); format.setTimeZone(TimeZone.getTimeZone("ETC/UTC")); try {//w ww .ja v a2 s .c o m Date date = format.parse(dateString); // System.out.println("Date ->" + date); calendar.setTime(date); return calendar; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String xmlSerialize(Date date) { if (date == null) { return null; }// ww w .ja v a2s. co m SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format((Date) date); }
From source file:Main.java
public static Date parseXmlDate(String xmlDateStr) throws Exception { if (xmlDateStr == null || xmlDateStr.trim().length() < 1) { return null; }/*from www . j a v a 2 s .c o m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(xmlDateStr); }
From source file:Main.java
public static final String dateToString(Date paramDate, String paramString) { SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString, Locale.FRANCE); localSimpleDateFormat.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); return localSimpleDateFormat.format(paramDate); }
From source file:Main.java
/** * Parsing the TimeZone of time in milliseconds. * * @param gmtTime GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}. * @return The number of milliseconds from 1970.1.1. * @throws ParseException if an error occurs during parsing. *//*from w ww . ja v a2s .co m*/ public static long parseGMTToMillis(String gmtTime) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US); formatter.setTimeZone(GMT_TIME_ZONE); Date date = formatter.parse(gmtTime); return date.getTime(); }
From source file:Main.java
public static long getLongDate(String date) { try {//from ww w .j av a 2 s . co m SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault()); sdf.setTimeZone(TimeZone.getDefault()); Date d = sdf.parse(date); return d.getTime(); } catch (Exception e) { e.printStackTrace(); } return 0; }
From source file:Main.java
public static SimpleDateFormat getEndDateTimeInTimezone(String timezone) { SimpleDateFormat format = new SimpleDateFormat("h:mm a"); if (timezone == null || timezone.isEmpty()) { format.setTimeZone(TimeZone.getDefault()); } else/* w w w. j a va 2 s . co m*/ format.setTimeZone(TimeZone.getTimeZone("GMT+" + timezone)); return format; }
From source file:Main.java
/** * Parsing the TimeZone of time from milliseconds. * * @param milliseconds the number of milliseconds from 1970.1.1. * @return GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}. *//* www . j a va 2s. c o m*/ public static String formatMillisToGMT(long milliseconds) { Date date = new Date(milliseconds); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US); simpleDateFormat.setTimeZone(GMT_TIME_ZONE); return simpleDateFormat.format(date); }
From source file:Main.java
public static String convertUtc2Local(String utcTime) { String time = ""; if (utcTime != null) { // 2014-10-24T02:58:05.932Z SimpleDateFormat utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CHINA); utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); Date gpsUTCDate = null;/*from w ww. j a va 2 s.c om*/ try { gpsUTCDate = utcFormatter.parse(utcTime); } catch (ParseException e) { e.printStackTrace(); } SimpleDateFormat localFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); localFormatter.setTimeZone(TimeZone.getDefault()); assert gpsUTCDate != null; time = localFormatter.format(gpsUTCDate.getTime()); } return time; }