Java8 New Date Time Class (2) __java

Source: Internet
Author: User
Tags string format
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);




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.