1 package guyu.day0831; 2 3 import java.text.ParseException; 4 import java.text.SimpleDateFormat; 5 import java.util.Date; 6 7 /** 8 * @Author: Fred 9 * @Date: 2020/8/31 09:17 10 */ 11 public class Demo01 { 12 public static void main(String[] args) { 13 14 //给定一个年月!获取每月每天所对应的星期 15 String s = "2020/8"; 16 SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/dd"); 17 sdf1.setLenient(false); 18 SimpleDateFormat sdf2 = new SimpleDateFormat("EEE"); 19 for (int i = 1; i < 32; i++) { 20 try { 21 Date date1 = sdf1.parse(s + "/" + i); 22 System.out.println(sdf1.format(date1) + " : " + sdf2.format(date1)); 23 } catch (ParseException e) { 24 //do nothing 25 } 26 } 27 28 System.out.println("---------------------------------"); 29 30 //获取当前的年月日时间(24小时制且区分上下午) 31 System.out.println("当前时间为:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss a").format(new Date())); 32 System.out.println("庚子年 【鼠年】 甲申月 丙午日 " + " "); 33 } 34 }
故屿γ