Since I read toString of java \ .time \ .LocalTime, I will write an example of using DateTimeFormatter as a memorandum.
It's just a memo writing.
Since slf4j is used for log output, pay attention to the dependency when actually running it.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class App {
private static final Logger logger = LoggerFactory.getLogger(App.class);
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
private static final DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss.SSS");
public static void main(String... args) {
var time = LocalTime.now();
logger.info(time.toString());
logger.info(time.format(formatter));
time = LocalTime.of(14,30);
logger.info(time.toString());
logger.info(time.format(formatter));
logger.info("---------------------");
var datetime = LocalDateTime.now();
logger.info(datetime.toString());
logger.info(datetime.format(formatter2));
datetime = LocalDateTime.of(2018,8,16,10,55);
logger.info(datetime.toString());
logger.info(datetime.format(formatter2));
}
}
16:08:49.562 [main] INFO App - 16:08:49.555999800
16:08:49.572 [main] INFO App - 16:08:49.555
16:08:49.572 [main] INFO App - 14:30
16:08:49.572 [main] INFO App - 14:30:00.000
16:08:49.572 [main] INFO App - ---------------------
16:08:49.572 [main] INFO App - 2018-08-16T16:08:49.572009800
16:08:49.573 [main] INFO App - 2018/08/16 16:08:49.572
16:08:49.573 [main] INFO App - 2018-08-16T10:55
16:08:49.573 [main] INFO App - 2018/08/16 10:55:00.000
Recommended Posts