Refine search
canonical example by Tabnine
public boolean isDateExpired(String input, Date expiration) throws ParseException { DateFormat dateFormat = new SimpleDateFormat ("dd/MM/yyyy"); Date date = dateFormat.parse(input); return date.after(expiration); }
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT")); //Local time zone SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); //Time in GMT return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
static String timeAsGmt() { SimpleDateFormat sdf = new SimpleDateFormat(); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); sdf.applyPattern("dd MMM yyyy HH:mm:ss z"); return sdf.format(Calendar.getInstance().getTime()); }
@Override public Object decode(Object jv) throws IOException { if (jv instanceof String) { try { return new SimpleDateFormat(DATE_FORMAT).parse((String) jv); } catch (ParseException e) { throw new IllegalArgumentException(e.getMessage(), e); } } if (jv instanceof Number) { return new Date(((Number) jv).longValue()); } return (Date) null; } };
private DateFormat newDateFormat() { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US); dateFormat.setTimeZone(GMT); return dateFormat; }
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); }
private long parseDateHeader(String name, String value) { for (String dateFormat : DATE_FORMATS) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat, Locale.US); simpleDateFormat.setTimeZone(GMT); try { return simpleDateFormat.parse(value).getTime(); } catch (ParseException ex) { // ignore } } throw new IllegalArgumentException("Cannot parse date value '" + value + "' for '" + name + "' header"); }
// Create an instance of SimpleDateFormat used for formatting // the string representation of date (month/day/year) DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); // Get the date today using Calendar object. Date today = Calendar.getInstance().getTime(); // Using DateFormat format method we can create a string // representation of a date with the defined format. String reportDate = df.format(today); // Print what date is today! System.out.println("Report Date: " + reportDate);
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()); }
/** * Sets the Date and Cache headers for the HTTP Response * * @param response * HTTP response * @param fileToCache * file to extract content type */ private static void setDateAndCacheHeaders(io.netty.handler.codec.http.HttpResponse response, File fileToCache) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); // Date header Calendar time = new GregorianCalendar(); response.headers().set(DATE, dateFormatter.format(time.getTime())); // Add cache headers time.add(Calendar.SECOND, HTTP_CACHE_SECONDS); response.headers() .set(EXPIRES, dateFormatter.format(time.getTime())) .set(CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS) .set(LAST_MODIFIED, dateFormatter.format(new Date(fileToCache.lastModified()))); }
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); }
Calendar c = Calendar.getInstance(); c.setTime(new Date(yourmilliseconds)); c.set(Calendar.MILLISECOND, 0); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm.ss.SSS'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); System.out.println(sdf.format(c.getTime()));
Date now = new Date(); // java.util.Date, NOT java.sql.Date or java.sql.Timestamp! String format1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH).format(now); String format2 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH).format(now); String format3 = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH).format(now); System.out.println(format1); System.out.println(format2); System.out.println(format3);
private String getTimeoutMessage(boolean scan) { long nowTimestamp = System.currentTimeMillis(); return (sent > 0 ? "Waiting server-side response timeout" : "Sending request timeout in client-side") + (scan ? " by scan timer" : "") + ". start time: " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(start))) + ", end time: " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date())) + "," + (sent > 0 ? " client elapsed: " + (sent - start) + " ms, server elapsed: " + (nowTimestamp - sent) : " elapsed: " + (nowTimestamp - start)) + " ms, timeout: " + timeout + " ms, request: " + request + ", channel: " + channel.getLocalAddress() + " -> " + channel.getRemoteAddress(); } }
UTC = TimeZone.getTimeZone("UTC"); TimeZone.setDefault(UTC); final Calendar c = new GregorianCalendar(UTC); c.set(1, 0, 1, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); BEGINNING_OF_TIME = c.getTime(); c.setTime(new Date(Long.MAX_VALUE)); END_OF_TIME = c.getTime(); final SimpleDateFormat sdf = new SimpleDateFormat(ISO_8601_24H_FULL_FORMAT); sdf.setTimeZone(UTC); System.out.println("sdf.format(BEGINNING_OF_TIME) = " + sdf.format(BEGINNING_OF_TIME)); System.out.println("sdf.format(END_OF_TIME) = " + sdf.format(END_OF_TIME)); System.out.println("sdf.format(new Date()) = " + sdf.format(new Date())); System.out.println("sdf.parse(\"2015-04-28T14:23:38.521Z\") = " + sdf.parse("2015-04-28T14:23:38.521Z")); System.out.println("sdf.parse(\"0001-01-01T00:00:00.000Z\") = " + sdf.parse("0001-01-01T00:00:00.000Z"));
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; }
/** * Sets the Date header for the HTTP response * * @param response * HTTP response */ private static void setDateHeader(FullHttpResponse response) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE)); Calendar time = new GregorianCalendar(); response.headers().set(DATE, dateFormatter.format(time.getTime())); }
final DateFormat format = new SimpleDateFormat("E. M/d"); final String dateStr = "Thu. 03/01"; final Date date = format.parse(dateStr); GregorianCalendar gregory = new GregorianCalendar(); gregory.setTime(date); XMLGregorianCalendar calendar = DatatypeFactory.newInstance() .newXMLGregorianCalendar( gregory);
@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))); }
protected List<TimePeriod> parseHolidays() { String holidaysString = businessCalendarConfiguration.getProperty(HOLIDAYS); List<TimePeriod> holidays = new ArrayList<TimePeriod>(); int currentYear = Calendar.getInstance().get(Calendar.YEAR); if (holidaysString != null) { String[] hPeriods = holidaysString.split(","); SimpleDateFormat sdf = new SimpleDateFormat(businessCalendarConfiguration.getProperty(HOLIDAY_DATE_FORMAT, "yyyy-MM-dd")); for (String hPeriod : hPeriods) { boolean addNextYearHolidays = false; Calendar tmpFrom = new GregorianCalendar(); if (timezone != null) { tmpFrom.setTimeZone(TimeZone.getTimeZone(timezone)); tmpFrom.setTime(sdf.parse(fromTo[0])); tmpTo.setTime(sdf.parse(fromTo[1])); tmpFrom.setTime(sdf.parse(fromTo[0])); tmpTo.setTime(sdf.parse(fromTo[1])); c.setTime(sdf.parse(fromTo[0])); holidays.add(new TimePeriod(sdf.parse(fromTo[0]), c.getTime())); tmp.setTime(sdf.parse(fromTo[0]));