Java correctly gets week Calendar.day_of_week
http://chamcon.iteye.com/blog/2144433
Java SimpleDateFormat time format conversion in Chinese and English
48089111
java-formatting dates with SimpleDateFormat
http://zy-email1991.iteye.com/blog/2243021
Write a Java program to convert time in AM/PM format to 24-hour format
Https://zhidao.baidu.com/question/1798461878119559747.html?qbl=relate_question_1&word=java%20am%20pm%20%D3 %a2%ce%c4
A demo written by a person:
ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.Locale;ImportJava.util.TimeZone; Public classMain { Public Static voidMain (string[] args) {Calendar Calendar=calendar.getinstance (Timezone.getdefault ()); //FAQ://1. National time format display and synchronization issues in different regions? UTC, Greenwich? Hawaii? Internationalization ~ Locale//2. Local client and server time synchronization issues, such as scheduled to execute the task, local scheduled time earlier than the current time of the server, you cannot executeSystem.out.println ("\ntimezone:" +Timezone.getdefault ()); LongTime =Calendar.gettimeinmillis (); Date Date1=Calendar.gettime (); Date Date2=NewDate ();//Get Current date//method1:direct format Fun call//A ~ am/pm, morning/AfternoonSimpleDateFormat SDF1 =NewSimpleDateFormat ("Yyyy-mm-dd hh:mm");//HH ~ 24-hour SystemSystem.out.printf ("\ntime1 in 24h:" +Sdf1.format (Calendar.gettime ())); SimpleDateFormat sdf11=NewSimpleDateFormat ("Yyyy-mm-dd hh:mm");//hh ~ 12-hour SystemSystem.out.printf ("\ntime11 in 12h:" +Sdf11.format (Calendar.gettime ())); SimpleDateFormat SDF2=NewSimpleDateFormat ("Yyyy-mm-dd a hh:mm", Locale.english); System.out.printf ("\ntime2:" +Sdf2.format (Calendar.gettime ())); SimpleDateFormat sdf3=NewSimpleDateFormat ("yyyy mm month DD Day hh:mm"); System.out.printf ("\ntime3:" +Sdf3.format (Calendar.gettime ())); SimpleDateFormat SDF4=NewSimpleDateFormat ("yyyy mm month DD Day a hh:mm"); System.out.printf ("\ntime4:" +Sdf4.format (Calendar.gettime ())); //method2:use Self define format func intYear =Calendar.get (calendar.year); intmonth =Calendar.get (Calendar.month); intDay =Calendar.get (Calendar.day_of_month); inthour =Calendar.get (Calendar.hour_of_day); intminute =Calendar.get (Calendar.minute); intSecond =Calendar.get (Calendar.second); //Europe and the United States the first day of the week is Sunday, which is written in the Java API code is dead, so here to manually make a judgment//The calendar of Monday, three or four, five or six, day, Day_of_week, etc., are in a constant form of existence,//we set Setfirstdayofweek () and cannot change the values of these constants intDayOfWeek = Calendar.get (Calendar.day_of_week);//gets the day of the week BooleanIsfirstsunday = (Calendar.getfirstdayofweek () = =calendar.sunday); if(isfirstsunday) {DayOfWeek-= 1; if(DayOfWeek = = 0) {DayOfWeek= 7; } } intDayofweekinmonth = Calendar.get (calendar.day_of_week_in_month);//the week ordinal of a month. By the number 1th, 1th is the 1th week, and 8th is the 2nd week. intWeekofmonth = Calendar.get (calendar.week_of_month);//the week ordinal of the month intDayOfYear = Calendar.get (calendar.day_of_year);//the day of the year, counting from number 1thSystem.out.println ("\ n" +Getformattedtime (year, month, day, hour, minute)); System.out.println ("\ndayofweek:" + DayOfWeek + "\ndayofweekinmonth:" +Dayofweekinmonth+ "\ndayofyear:" +dayofyear); } /*** Formatted date string, like xx xx month xx Day xx:xx:xx *@paramYear *@paramMonth *@paramDay *@paramHour *@paramminute *@returnString*/ Public StaticString Getformattedtime (intYearintMonthintDayintHourintminute) {String Yearstr= ""; String Monthstr= ""; String Daystr= ""; String Hourstr= ""; String Minutestr= ""; // Year if(Year < 10) {Yearstr= "0" +Year ; } Else{yearstr=string.valueof (year); } //Month if(Month < 10) {Monthstr= "0" +month; } Else{monthstr=integer.tostring (month); } // Day if(Day < 10) {Daystr= "0" +Day ; } Else{daystr=integer.tostring (day); } //Hour if(Hour < 10) {Hourstr= "0" +hour; } Else{hourstr=integer.tostring (hour); } //minute if(Minute < 10) {Minutestr= "0" +minute; } Else{minutestr=integer.tostring (minute); } returnYearstr + "Year" + Monthstr + "Month" + daystr + "Day" + Hourstr + ":" +Minutestr; }}
Java Date Time Acquisition and display