List of usage examples for java.text SimpleDateFormat setTimeZone
public void setTimeZone(TimeZone zone)
From source file:Main.java
/** * To date string.//from w w w. j a v a2 s . com * * @param date the date * @return the date */ @SuppressLint("SimpleDateFormat") public static Date toDateString(String date) { String formatoFecha = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; SimpleDateFormat sdf = new SimpleDateFormat(formatoFecha); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); try { return date == null ? null : sdf.parse(date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:Main.java
private static SimpleDateFormat getApiSimpleDateFormat() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(API_DATE_FORMAT, Locale.getDefault()); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat; }
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); return formatter.format(aDate); }
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 {/*ww w .ja va 2 s .c o 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
/** * Converts a Date to the GMT timezone and formats it to the format yyyy-MM-dd HH:mm:ssZ. * * @param date the Date to parse.//from w w w.ja v a 2 s . com * @return A formatted date string. */ public static String getLongGmtDateString(Date date) { if (date == null) { return null; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat.format(date); }
From source file:Main.java
public static Date ConvertFromWebService(final String strDate) { final String[] formats = new String[] { "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" }; for (final String frm : formats) { try {/* w w w . j a va 2 s . com*/ final SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); return format.parse(strDate); } catch (final Exception ex) { Log.e("IGWHelper", "Failed to convert Web Service Date.", ex); } } return null; }
From source file:Main.java
public static String getDate(String integer) { SimpleDateFormat sdf = new SimpleDateFormat("EEEE,MMMM d,yyyy h:mm,a", Locale.ENGLISH); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String formattedDate = sdf.format(new Date()); if (!integer.equalsIgnoreCase("null")) { long seconds = Integer.valueOf(integer); long millis = seconds * 1000; Date date = new Date(millis); formattedDate = sdf.format(date); return formattedDate; }//from w w w.j a va 2s . c om return formattedDate; }
From source file:Main.java
/** * Parse a time character array as defined in PKCS#11 and return is as a * Date object.//from w ww.j a va2 s .c o m * * @param timeChars A time encoded as character array as specified in PKCS#11. * @return A Date object set to the time indicated in the given char-array. * null, if the given char array is null or the format is wrong. * @preconditions * @postconditions */ public static Date parseTime(char[] timeChars) { Date time = null; if ((timeChars != null) && timeChars.length > 2) { String timeString = new String(timeChars, 0, timeChars.length - 2); try { SimpleDateFormat utc = new SimpleDateFormat("yyyyMMddhhmmss"); utc.setTimeZone(TimeZone.getTimeZone("UTC")); time = utc.parse(timeString); // time = new SimpleDateFormat("yyyyMMddhhmmss").parse(timeString); } catch (ParseException ex) { /* nothing else to be done */ } } return time; }
From source file:Main.java
public static String getCurrentUTCTime() { SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); Date t = new Date(); df1.setTimeZone(TimeZone.getTimeZone("UTC")); return df1.format(t); }
From source file:Main.java
public static Date parseTimestamp(String timestamp) { for (SimpleDateFormat format : ACCEPTED_TIMESTAMP_FORMATS) { format.setTimeZone(TimeZone.getTimeZone("GMT")); try {/*from www.ja v a 2 s. co m*/ return format.parse(timestamp); } catch (ParseException ex) { continue; } } // All attempts to parse have failed return null; }