当前位置:网站首页>Simpledateformat concrete classes for formatting and parsing dates

Simpledateformat concrete classes for formatting and parsing dates

2022-06-24 23:22:00 Programmer Jiuan

SimpleDateFormat Specific classes for formatting and parsing dates

 Insert picture description here

 	SimpleDateFormat sdf = new SimpleDateFormat("yyyy year MM month dd Japan  HH when mm branch ss second ");
 	 Date to string 

 y  Represents the year     M  Representative month      d  On behalf of the day      E  On behalf of the week      H  representative 24 Decimal hours      h  representative 12 Decimal hours  
 m  For minutes        s  On behalf of the second       ( uppercase )S  On behalf of ms 
 		// Format date as text 
 	  	String format = sdf.format(date);
        System.out.println(format);//2021 year 05 month 26 Japan  16 when 23 branch 01 second 
		// Parse the string to Date Time 
		 Date parse = sdf.parse("2021 year 05 month 26 Japan  16 when 07 branch 25 second ");
        System.out.println(parse);//Wed May 26 16:07:25 CST 2021

 Insert picture description here

		 Date date1 = new Date();
        // Judge whether the current time is between or after the set time 
        boolean after = date1.after(parse);
        System.out.println(" Current time is after the set time :"+after);
        boolean before = date1.before(parse);
        System.out.println(" The current time is before the set time :"+before);

原网站

版权声明
本文为[Programmer Jiuan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241745464189.html