Java.time Time zone datetime class
Java.time the primary class for processing local datetime is Zoneddatetime, which is typically used to replace localdate when the time zone used for the region needs to be considered;
Zoneddatetime
Static Construction Method Summary |
Static Zoneddatetime Static Zoneddatetime
Static Zonedatetime
Static Zoneddatetime
|
Now () of (int year,int month,int dayofmonth,int hour,int minute[,int second[,int nanoseconds]], Zonid zone) of (LocalDateTime Localdatetime,zonid Zone)
Parse(charsequence text)
|
Constructs a LocalDateTime object using the current time Creates a LocalDateTime object with the specified number (Year,month,day starting from 1, Hour,min,second starting from 0)
Create using the specified LocalDateTime object
Create an object using a format such as "2017-2-28t13:29:30[europe/pair]"
|
Member Method Summary |
+localdate +localtime +localdatetime
+zoneddatetime +int +zoneddatetime
+string
|
tolocaldate () ToLocalTime () Tolocaldatetime ()
with (Temporalfield Field,long value) Get (Temporalfield field) Plus (Temporalamount Amouttoadd) Plus (Long amounttoadd,temporaunit Unit)
toString () |
Gets the Localdate object for this object Gets the LocalTime object for this object Gets the LocalDateTime object for this object
Modify Zoneddatetime Time numeric parameters (can be chained to call) Gets the time numeric parameter of the Zoneddatetime The elapsed amount of a time parameter value for a zoneddatetime
String format: 2017-2-28t13:29:30[eurpe/paris] |
Note: LocalDateTime's
With,get,plus
method, all have the realization of a single filed
with[filed] (int Filed), such as withdayofmonth (int days), the main field values are as follows:
With,get: year,month,dayofmonth,hour,minute,second,dayofyear,zonesanmelocal (ZoneID zone);
Plus: Years,months,weeks,days,hours,minutes,seconds,nanos;
The ZoneID classes are constructed as follows:
ZoneID zone = Zoneid.systemdefault (); Use the system time zone ZoneID zone = zoneid.of ("CTT"); Use a predefined time zone ZoneID string constant as follows: EST- -05:00 HST- -10:00 MST- -07:00 act-australia/darwin Aet-australia/sydney agt-a Merica/argentina/buenos_aires Art-africa/cairo ast-america/anchorage Bet-america/sao_paulo Bst-asia/dhaka CAT-AF Rica/harare cnt-america/st_johns cst-america/chicago Ctt-asia/shanghai Eat-africa/addis_ababa ect-europe/paris I Et-america/indiana/indianapolis ist-asia/kolkata Jst-asia/tokyo Mit-pacific/apia Net-asia/yerevan nst-pacific/ Auckland Plt-asia/karachi Pnt-america/phoenix Prt-america/puerto_rico pst-america/los_angeles sst-pacific/guadal Canal Vst-asia/ho_chi_minh can also customize the ZoneID time zone offset
ZoneID zone = Zoneid.ofoffset ("UTF", zoneoffset.ofhours (8));
backward compatibility of Java8
Converts a Date object to a LocalDateTime object
Import Java.time.LocalDateTime; Import Java.util.Date; Import java.time.Instant; Import Java.time.ZoneId; ... Date date = new Date ();
Instant Instant = Date.toinstant ();LocalDateTime LocalDateTime = LocalDateTime.
ofinstant(Instant,zoneid.systemdefault);