Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Java Program to create custom DateTime formatter

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
public class Demo {
	public static void main(String[] args) {
		DateTimeFormatter dtFormat =  new DateTimeFormatterBuilder()
		.appendValue(ChronoField.HOUR_OF_DAY)
		.appendLiteral(":")
		.appendValue(ChronoField.MINUTE_OF_HOUR)
		.appendLiteral(":")
		.appendValue(ChronoField.SECOND_OF_MINUTE)
		.toFormatter();
		System.out.println("Time = "+dtFormat.format(LocalDateTime.now()));
		dtFormat =  new DateTimeFormatterBuilder()
		.appendValue(ChronoField.YEAR)
		.appendLiteral("/")
		.appendValue(ChronoField.MONTH_OF_YEAR)
		.appendLiteral("/")
		.appendValue(ChronoField.DAY_OF_MONTH)
		.toFormatter();
		System.out.println("Date = "+dtFormat.format(LocalDateTime.now()));
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.