美文网首页Android
DateTimeFormatter Demo

DateTimeFormatter Demo

作者: JaedenKil | 来源:发表于2018-10-15 16:15 被阅读4次
    import java.time.LocalDateTime;
    import java.time.format.DateTimeFormatter;
    
    public class DateFormatter {
        public static void main(String[] args) {
            //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/mm/dd-hh:mm:ss");
            //2018/06/15-04:06:13
            //DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd-hh:mm:ss");
            //2018/10/15-04:06:49
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd-HH:mm:ss");
            //2018/10/15-16:07:40
            DateTimeFormatter timestampFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
            //20181015161416
            LocalDateTime now = LocalDateTime.now();
            String date = dateTimeFormatter.format(now);
            String timestamp = timestampFormatter.format(now);
            System.out.println(date);
            System.out.println(timestamp);
        }
    }
    

    So MM stands for month, and mm stands for minute.
    HH stands for hour in 24-hour clock, hh stands for hour in 12-hour clock.
    Generate a timestamp? Pattern yyyyMMddHHmmss will do.

    相关文章

      网友评论

        本文标题:DateTimeFormatter Demo

        本文链接:https://www.haomeiwen.com/subject/ytgfzftx.html