Java Utililty Methods DateTimeFormatter

List of utility methods to do DateTimeFormatter

Description

The list of methods to do DateTimeFormatter are organized into topic(s).

Method

LocalDateTimeformatDate(long timestamp)
format Date
return LocalDateTime.ofEpochSecond(timestamp / 1_000, 0, ZoneOffset.UTC);
StringformatDate(long timestamp)
format Date
return Instant.ofEpochMilli(timestamp).atZone(UTC_ZONE).format(DATE_PARSER_FORMATTER);
LocalDateTimeformatDateAndTime(String dateAndTime)
Parses a String to a LocalDateTime object like for example to '2015-12-15 12:30';
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime formatedDate = LocalDateTime.parse(dateAndTime, formatter);
return formatedDate;
StringformatDateTime(Date dateTime)
Format a date/time to YYYY-MM-dd HH:mm:ss format
return dateTimeFormatter.format(dateTime);
StringformatDateTime(long milis)
format Date Time
LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(milis), ZoneId.systemDefault());
return DTF.format(dateTime);
StringformatISOUTCDateTime(long timestamp)
format ISOUTC Date Time
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC);
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
return formatter.format(zonedDateTime);
StringformatNow(String format)
format Now
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
return utcNow().format(formatter);
StringformatTime(long milliSeconds)
Formats a timestamp in a format suitable to be presented to the user using the current timezone.
return formatTime(milliSeconds, currentZoneId);
StringformatTimestamp(long timestamp)
format Timestamp
return Instant.ofEpochMilli(timestamp).atZone(ZoneId.of("UTC")).toLocalDateTime()
        .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
StringformatTimestap(final long timestap)
format Timestap
return DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.ENGLISH)
        .format(Date.from(Instant.ofEpochMilli(timestap)));