J'ai lu java \ .time \ .LocalTime toString, donc j'écrirai un exemple d'utilisation de DateTimeFormatter comme mémorandum.
C'est juste une rédaction de mémo.
Puisque slf4j est utilisé pour la sortie du journal, faites attention à la dépendance lors de son exécution.
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