public static String toString(java.util.Date date) { if (date == null) { return null; } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return format.format(date); }
public static String getCurrentTimeAsString() { SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); return format.format(new Date()); } }
public final String formatUTCTZ(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.format(date); }
public static List<String> getOldWeekDays() { final Calendar c = Calendar.getInstance(); String[] months = new String[8]; for (int i = 0; i < 8; i++) { months[i] = new SimpleDateFormat("MM.dd").format(new Date(c .getTimeInMillis())); c.add(Calendar.DAY_OF_MONTH, -1); } return Arrays.asList(months); }
private void printStartInfo() { Date currentDate = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(currentDate); calendar.add(Calendar.SECOND, runTime); Date finishDate = calendar.getTime(); StringBuilder startInfo = new StringBuilder(dateFormat.format(currentDate)); startInfo.append(" ready to start client benchmark"); startInfo.append(", concurrent num is ").append(concurrents); startInfo.append(", the benchmark will end at ").append(dateFormat.format(finishDate)); System.out.println(startInfo.toString()); }
public static String dateToString(Date date) { if (date != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN); simpleDateFormat.setTimeZone(UTC); return simpleDateFormat.format(date); } return ""; } }
@Override public String toString() { return new SimpleDateFormat(DATE_PATTERN).format(calendar.getTime()); }
private void checkParse(final Locale locale, final Calendar cal, final SimpleDateFormat sdf, final DateParser fdf) throws ParseException { final String formattedDate= sdf.format(cal.getTime()); checkParse(locale, sdf, fdf, formattedDate); checkParse(locale, sdf, fdf, formattedDate.toLowerCase(locale)); checkParse(locale, sdf, fdf, formattedDate.toUpperCase(locale)); }
public String getCurTime() { String fromTimeZone = "GMT+8"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); format.setTimeZone(TimeZone.getTimeZone(fromTimeZone)); String chinaDate = format.format(date); return chinaDate; }
public static String getCurrentTimeAsString() { SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); return format.format(new Date()); } }
@Test public void testCalendar() { Date d = new Date(0); Calendar cal = Calendar.getInstance(); cal.setTime(d); assertThat(jdkTypeToJson(cal), containsString(new SimpleDateFormat("yyyy-MM-dd").format(d))); }
public static String dateToString(Date date) { if (date != null) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN); simpleDateFormat.setTimeZone(UTC); return simpleDateFormat.format(date); } return ""; } }
@Override public void encode(Object obj, JSONWriter jb) throws IOException { jb.valueString(new SimpleDateFormat(DATE_FORMAT).format((Date) obj)); } };
@Override public String format(String pattern) { try { return String.format(pattern, calendar); } catch (NullPointerException npe) { return new SimpleDateFormat(DATE_PATTERN).format(calendar.getTime()); } }
/** * @param timeInMilliSeconds - The time in milliseconds * @param format - A format that can be used by {@link SimpleDateFormat} * @return - A formatted string representation of the time in UTC/GMT timezone. */ public static String timeInUTC(long timeInMilliSeconds, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); TimeZone utc = TimeZone.getTimeZone("UTC"); sdf.setTimeZone(utc); return sdf.format(timeInMilliSeconds); } }
/** * Returns a String representing the current date and time in the given * format. * * @see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a> */ public static String getTimestampString(String fmt) { return (new SimpleDateFormat(fmt)).format(new Date()); }
String computeTimeStampString(long now) { synchronized (this) { // Since the formatted output is only precise to the second, we can use the same cached string if the // current // second is the same (stripping off the milliseconds). if ((now / 1000) != lastTimestamp) { lastTimestamp = now / 1000; Date nowDate = new Date(now); calendar.setTime(nowDate); timesmapStr = String.format("%s %2d %s", simpleMonthFormat.format(nowDate), calendar.get(Calendar.DAY_OF_MONTH), simpleTimeFormat.format(nowDate)); } return timesmapStr; } } }
String getStartDateTime() { if (startDateTime == null) { SimpleDateFormat format = new SimpleDateFormat( "EEE, d MMM yyyy HH:mm:ss z", new Locale("en", "")); format.setTimeZone(DateTimeUtils.UTC); startDateTime = format.format(System.currentTimeMillis()); } return startDateTime; }