Time API

Date:

        // get the current timestamp value with millisecond 
        Long L = System.currentTimeMillis ();
         // get local time 
        a Date DATE = new new a Date ();
         // pass the object in terms of the time stamp 
        a Date X = new new a Date (L);
         / / acquires a time stamp 
        Long Time = date.getTime ();
         // DATE formatting and parsing can be configured using the control format string 
        the SimpleDateFormat SimpleDateFormat = new new the SimpleDateFormat ();
         // formatted string 
        string the format = simpleDateFormat.format ( DATE);
         // parse STR 
        simpleDateFormat.parse (the format);

Calendar:

        // abstract class
 //         Method 1: Create a subclass of 
        GregorianCalendar GregorianCalendar = new new GregorianCalendar ();
         // Second way: call getInstance 
        Calendar instance = Calendar.getInstance ();
         // get the first few days of the month depends on constant 
        int i = instance.get (Calendar.DAY_OF_MONTH);
         // the first few days of the month depends on constant change 22 days 
        instance.set (Calendar.DAY_OF_MONTH, 22 );
         // the first few days of the month plus one day 
        instance. the Add (Calendar.DAY_OF_MONTH,. 1 );
         // get a date 
        a date time = instance.getTime ();
         // incoming date setting time
        instance.setTime(time);

LOCALDATE:

        /*
        java8 new java.time
         * / 
        // Date of 
        the LocalDate DATE = LocalDate.now ();
         // time 
        LocalTime TIME1 = LocalTime.now ();
         // date and time 
        the LocalDateTime LocalDateTime = LocalDateTime.now ();
         // no offset 
        LocalDateTime dateTime = LocalDateTime .of (2020, 1, 1, 0, 0, 0, 0 );
         // this month the first few days 
        int dayOfMonth = localdatetime.getDayOfMonth ();
         // set the first 22 days of the month 
        the LocalDateTime the LocalDateTime = localdatetime.withDayOfMonth (22 ) ;
         // playback time there is an increase
        localdateti to localdatetime1 = localdatetime.plusdays (1);

Instant: instantaneous:

        // instantiate the prime meridian London time to give 
        the Instant Instant = Instant.now ();
         // Set the Prime Meridian equal zone plus eight hours 
        OffsetDateTime OffsetDateTime = instant.atOffset (ZoneOffset.ofHours (. 8 ));
         // Get timestamp 
        Long L = instant.toEpochMilli ();
         // instantiation time 
        Instant instant1 = Instant.ofEpochMilli (l);

DateTimeFormatter: date and time format or parse

        // Create an object 
        the DateTimeFormatter DateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
         // Format 
        String the format = dateTimeFormatter.format (LocalDateTime.now ());
         // parse 
        TemporalAccessor the parse = dateTimeFormatter.parse (the format);
         // create the object parameter determines the output format 
        = dateTimeFormatter1 the DateTimeFormatter DateTimeFormatter.ofLocalizedDateTime (FormatStyle.FULL);
         // custom created 
        DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern ( "yyyy- mM-dd hh: mm: ss");

Guess you like

Origin www.cnblogs.com/aikang525/p/12115381.html