List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:Main.java
public static String formatTime(long millisecond) { DateFormat format = new SimpleDateFormat("mm:ss"); format.setTimeZone(TimeZone.getTimeZone("GMT+00:00")); return format.format(millisecond); }
From source file:TimeUtils.java
public static String formatDuration(long duration) { SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss:SSS"); format.setTimeZone(TimeZone.getTimeZone("GMT")); return format.format(new Date(duration)); }
From source file:Main.java
public static String toIsoDateFormat(Date date) { TimeZone timeZone = TimeZone.getDefault(); boolean utc = TimeZone.getTimeZone("UTC").equals(timeZone) || TimeZone.getTimeZone("GMT").equals(timeZone); String pattern = utc ? "yyyy-MM-dd'T'HH:mm:ss'Z'" : "yyyy-MM-dd'T'HH:mm:ssZ"; SimpleDateFormat format = new SimpleDateFormat(pattern); format.setTimeZone(timeZone);//from www. j a v a 2 s . co m StringBuilder buffer = new StringBuilder(format.format(date)); if (!utc) { buffer.insert(buffer.length() - 2, ':'); } return buffer.toString(); }
From source file:Main.java
public static String toNumberDate(Date date) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.format(date); }
From source file:Main.java
public static SimpleDateFormat getDateFormat() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format; }
From source file:Main.java
public static String getCurrentTime(String format) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault()); sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); String currentTime = sdf.format(date); return currentTime; }
From source file:Main.java
public static String getMonth(final Date date) { if (date != null) { Calendar calendar = Calendar.getInstance(); TimeZone timeZone = TimeZone.getTimeZone("GMT+8"); calendar.setTimeZone(timeZone);/*from w ww . j a va 2 s.com*/ calendar.setTime(date); return String.valueOf(calendar.get(Calendar.MONTH) + 1); } return "0"; }
From source file:Main.java
/** Gets current time in UTC. */ public static Calendar getCurrentCalendarTimeUtc() { Calendar currentTime = Calendar.getInstance(TimeZone.getTimeZone(UTC_TIME_ZONE_ID)); return currentTime; }
From source file:Main.java
public static long stringDateToLong(String dateStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); Date date = null;/*ww w . j a v a 2s. c o m*/ try { date = sdf.parse(dateStr); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date.getTime(); }
From source file:Main.java
public static SimpleDateFormat getDateTimeFormat() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format; }