@Override public Instant parse(String text, Locale locale) throws ParseException { if (text.length() > 0 && Character.isDigit(text.charAt(0))) { // assuming UTC instant a la "2007-12-03T10:15:30.00Z" return Instant.parse(text); } else { // assuming RFC-1123 value a la "Tue, 3 Jun 2008 11:05:30 GMT" return Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(text)); } }
public static void main(String[] args) { System.out.println("Hello World!"); /* Issue1: Display total amount of free memory available to the JVM/User */ System.out.println("Free memory (bytes): " + Runtime.getRuntime().freeMemory()); /* Issue2: Display the current date to the user */ System.out.print( java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME .format(java.time.ZonedDateTime.now()) .replaceFirst(".....$", "GMT") + ": "); // replace UTC offset with GMT }
public static String getRfc1123FormattedDateTime() { ZonedDateTime now = ZonedDateTime.now(ZoneId.of("GMT")); return DateTimeFormatter.RFC_1123_DATE_TIME.format(now); }
private String resolveLastModifiedRFC1123() { Instant instant = new Date(lastModified).toInstant(); ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.of("GMT")); return DateTimeFormatter.RFC_1123_DATE_TIME.format(zonedDateTime); }