List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:Main.java
public static final String getStringTimeFromLong(final long timeInMillis) { final SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy HH:mm"); final Calendar c = Calendar.getInstance(); c.setTimeInMillis(timeInMillis);//www .j ava 2 s . c o m c.setTimeZone(TimeZone.getDefault()); return format.format(c.getTime()); }
From source file:Main.java
public static String timestamp2String(Timestamp timestamp, String pattern, Locale locale) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, locale); simpleDateFormat.setTimeZone(TimeZone.getDefault()); return simpleDateFormat.format(timestamp); }
From source file:Main.java
/** * converts time to UTC format//from ww w.j av a 2 s.c om */ public static String getHourFormatted(Date createdUTC) { Date dateServer = createdUTC; TimeZone.setDefault(TimeZone.getTimeZone("GMT")); Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date dateGMT = cal.getTime(); return normalDateFormat(dateServer); }
From source file:Main.java
private static String createDate(Date date, String defaultFormat, Boolean utc) { SimpleDateFormat gmtFormat = new SimpleDateFormat(); gmtFormat.applyPattern(defaultFormat); TimeZone gmtTime = (utc) ? TimeZone.getTimeZone("GMT") : TimeZone.getDefault(); gmtFormat.setTimeZone(gmtTime);/* w w w . j a v a 2 s . c o m*/ return gmtFormat.format(date); }
From source file:Main.java
public static long getLongDate(String date) { try {// w ww . ja v a 2 s .c o 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
@SuppressLint("SimpleDateFormat") static String futureDate() { // take current date and increment Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date currentLocalTime = cal.getTime(); SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd"); date.setTimeZone(TimeZone.getDefault()); _currentDate = date.format(currentLocalTime); try {/*from w ww . j a v a 2s.co m*/ cal.setTime(date.parse(_currentDate)); } catch (ParseException e) { e.printStackTrace(); } cal.add(Calendar.DATE, 30); _currentDate = date.format(cal.getTime()); return _currentDate; }
From source file:Main.java
public static LocalDateTime getDateTimeFromTimestamp(long timestamp) { if (timestamp == 0) return null; return LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), TimeZone.getDefault().toZoneId()); }
From source file:Main.java
public static String getLocalTimeFromUTC(String UTCTime) { java.util.Date UTCDate = null; String localTimeStr = null;//ww w .j a v a 2 s .c om SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); try { UTCDate = format.parse(UTCTime); localTimeStr = format.format(UTCDate.getTime() + TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return localTimeStr; }
From source file:Main.java
public static String getUTCTimeFromLocal(String localTime) { java.util.Date UTCDate = null; String localTimeStr = null;/*ww w . ja v a2s.c o m*/ SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); try { UTCDate = format.parse(localTime); localTimeStr = format.format(UTCDate.getTime() - TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return localTimeStr; }
From source file:Main.java
public static String getLocalDateTimeFromUTCDateTime(String UTCDateTime) { java.util.Date nowDate = null; String UTCDate = null;/* w w w .j a v a 2 s.c o m*/ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); try { nowDate = format.parse(UTCDateTime); UTCDate = format.format(nowDate.getTime() + TimeZone.getDefault().getRawOffset()); } catch (ParseException e) { e.printStackTrace(); } return UTCDate; }