List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:Main.java
public static DateFormat getZuluFormat() { if (mZuluFormat == null) { //Format used by SharePoint for encoding datetimes mZuluFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); mZuluFormat.setTimeZone(TimeZone.getTimeZone("GMT")); }// w w w .j ava2s . c om return mZuluFormat; }
From source file:Main.java
/** * Turns a Java date object into a mySQL acceptable date string * * @param date/* w ww.jav a2 s . c o m*/ * Date object * @return mySQL acceptable date string */ public static String toSQLDateString(Date date, String timezone) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getTimeZone(timezone)); return dateFormat.format(date); }
From source file:Main.java
public static String encodeTimeInstant(Date aDate) { TimeZone utcTimeZone = TimeZone.getTimeZone("UTC"); SimpleDateFormat formatter = new SimpleDateFormat(TIME_INSTANT_FORMAT); formatter.setTimeZone(utcTimeZone);/*from w w w .j a v a2 s . co m*/ return formatter.format(aDate); }
From source file:Main.java
/** * Returns a string suitable for the date for a cookie. * //from w w w. j ava 2 s. co m * @return a string suitable for the date for a cookie */ public static String createCookieDate() { // Wdy, DD-Mon-YYYY HH:MM:SS GMT Format f = new SimpleDateFormat("E, dd-MM-yyyy kk:mm:ss"); Date date = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime(); return f.format(date) + " GMT"; }
From source file:Main.java
public static String getDaysWithoutYear(String srcDate) { SimpleDateFormat parserSDF = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat formater = new SimpleDateFormat("MM/dd"); Date date = null;//from ww w . j a va 2 s . c o m try { parserSDF.setTimeZone(TimeZone.getTimeZone("UTC")); date = parserSDF.parse(srcDate); } catch (ParseException e) { Log.d(TAG, e.getMessage()); } return formater.format(date); }
From source file:Main.java
/** * Parse the Date String in mySQL format into date object * /* ww w.j av a 2s . co m*/ * @param SQLDate the date String in SQL format ("yyyy-MM-dd HH:mm:ss") * @return The date object corresponding to SQLDate */ public static Date parseSQLDate(String SQLDate) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); return sdf.parse(SQLDate, new ParsePosition(0)); }
From source file:Main.java
/** * Convert Date to String in HK TimeZone * @param date//from www .ja va2 s . c om * @param format Format of the output string (e.g. "yyyy-MM-dd HH:mm:ss", "HH:mm:ss") * @return output string */ public static String convertDateToStr(Date date, String format) { SimpleDateFormat dateFormat = new SimpleDateFormat(format, Locale.ENGLISH); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+0000")); String dateStr = ""; if (date != null) { dateStr = dateFormat.format(date); } else { dateStr = dateFormat.format(new Date()); } return dateStr; }
From source file:Main.java
public static String getDate(long time, String format) { TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai"); TimeZone.setDefault(tz);//from w ww .ja va 2 s . c om String datetime = ""; Date date = new Date(time); SimpleDateFormat sdf = new SimpleDateFormat(format); datetime = sdf.format(date); return datetime; }
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 w w . j a v a2 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; }
From source file:Main.java
public static Date getTimeFrom(int year, int month, int day, int hour, int minute, int second) { Calendar calendar = new GregorianCalendar(year, month, day, hour, minute, second); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); return calendar.getTime(); }