第七周

第七周学习总结及第八周计划

          本周学习内容:1.完成Java的基础类的学习

                                    2.认真分析学习Java各个基础类的作用

                                    2.简单了解学习了Java的集合

             下周计划:1.学习Java的集合,了解其作用

                               2.了解Java的泛型及其作用

             遇到的问题:Java时间,日期格式器的使用:

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Locale;

public class DateTimeFormatterDemo {
public static void main(String[] args) {
LocalDate localDate = LocalDate.now();

DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("MMM dd, yyyy");
String formattedDate1 = formatter1.format(localDate);
System.out.println(formattedDate1); //Dec 17, 2018

DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("MMM dd, yyyy", Locale.CANADA);
String formattedDate2 = formatter2.format(localDate);
System.out.println(formattedDate2); //Dec. 17, 2018

DateTimeFormatter formatter3 = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL);
String formattedDate3 = formatter3.format(localDate);
System.out.println(formattedDate3); //Monday, December 17, 2018

LocalDateTime localDateTime = LocalDateTime.now();

DateTimeFormatter formatter4 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
String formattedDate4 = formatter4.format(localDateTime);
System.out.println(formattedDate4); //Dec 17, 2018, 9:14:39 PM

DateTimeFormatter formatter5 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT);
String formattedDate5 = formatter5.format(localDateTime);
System.out.println(formattedDate5); //December 17, 2018, 9:14 PM

LocalTime localTime = LocalTime.now();

DateTimeFormatter formatter6 = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
String formattedDate6 = formatter6.format(localTime);
System.out.println(formattedDate6); //9:14:39 PM
}
}

posted on 2022-08-13 23:00  樱华旧梦  阅读(76)  评论(0)    收藏  举报