List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:Main.java
public static String getUTCDateTimeFromLocalDateTime(String localTimeStr) { java.util.Date nowDate = null; String UTCDate = null;// w w w . j av a 2 s. c om SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); try { nowDate = format.parse(localTimeStr); UTCDate = format.format(nowDate.getTime() - TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return UTCDate; }
From source file:Main.java
/** * getStringAsDate/*from www .j a v a2 s . c o m*/ * * @param dateString a string in date format * @param format the resulting date format * @return a new date in the specified format */ public static Date getStringAsDate(String dateString, String format, String timezone) { SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault()); if (timezone == null) { formatter.setTimeZone(TimeZone.getDefault()); } else { formatter.setTimeZone(TimeZone.getTimeZone("UTC")); } Date date = new Date(); try { date = formatter.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
@SuppressWarnings("unused") private static int getDefaultTimeZoneRawOffset() { return TimeZone.getDefault().getRawOffset(); }
From source file:Main.java
public static Function<Date, XMLGregorianCalendar> fromDate() { return new Function<Date, XMLGregorianCalendar>() { @Override//from w w w .j a v a 2s. co m public XMLGregorianCalendar apply(final Date date) { if (date == null) return null; return new XMLGregorianCalendarImpl(new GregorianCalendar(TimeZone.getDefault()) { { setTime(date); } }); } }; }
From source file:Main.java
public static long getDateMills(int year, int month, int day) { //Date d = new Date(year, month, day); // 1960 4 22//from ww w.ja va 2 s . c o m Calendar calendar = Calendar.getInstance(Locale.CHINA); calendar.set(year, month, day); TimeZone tz = TimeZone.getDefault(); calendar.setTimeZone(tz); return calendar.getTimeInMillis(); }
From source file:Main.java
public static String getTimezone() { return TimeZone.getDefault().getID(); }
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 ww w . j a va2s .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; }
From source file:Main.java
public static String getConvertDate(String dateStr) { SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy"); String dateString = dateStr.replace("Z", "GMT+00:00"); dateFormat.setTimeZone(TimeZone.getDefault()); Date date = null;// w w w.j ava2 s. c o m try { date = dateFormat.parse(dateString); } catch (java.text.ParseException e1) { e1.printStackTrace(); } dateFormat = new SimpleDateFormat("hh:mm a - dd MMM yy"); String outputText = dateFormat.format(date); return outputText; }
From source file:Main.java
public static TimeZone getTimeZone(final String id) { if (id == null) return TimeZone.getDefault(); else//w w w.ja v a 2 s . co m return TimeZone.getTimeZone(id); }
From source file:Main.java
public static String getCurrentTimeZoneID() { //String timezonePropertyValue = SecurityActions.getSystemProperty(GeneralConstants.TIMEZONE, "GMT"); TimeZone timezone;/*from www. ja va2 s . c o m*/ //if (GeneralConstants.TIMEZONE_DEFAULT.equals(timezonePropertyValue)) { timezone = TimeZone.getDefault(); //} else { // timezone = TimeZone.getTimeZone(timezonePropertyValue); //} System.out.println("TIMEZONE:" + timezone.getID()); return timezone.getID(); }