Changes in time and data in Java8

Source: Internet
Author: User
Tags time and seconds

Java8 In addition to the lambda expression on the time and the array of these two commonly used APIs should be adjusted,

Stream has several common functions:

Store sort (A, a, b) A.compareto The result is a positive order, from small to large if (a, B)->b.compareto (a) out of the result is from large to small

Filter intercept, filter. Filter by condition

Foreeach iterate over each element

Map Change or replace

Limit length or number of compliance limits

Skip jumps to a start point, and the skip and limit combinations can create pagination effects

Sum, Count is the general aggregation parameter

Distinct de-duplication, the deduplication comparison here is whether two objects are equal Object.equal (object). Cannot be implemented according to a field property to go to weight. Of course, it doesn't fit the normal logic.

PS: The cycles required for these combinations are one-time, highly efficient

JAVA8 API for Date time

1       //Update for JAVA8 time API2Clock clock=CLOCK.SYSTEMUTC ();3 System.out.println (Clock.millis ());4         //Time Line Instant5Instant Instant =Instant.now ();6Thread.Sleep (1000);7Instant end =Instant.now ();8         //Time interval Duration9Duration duration=Duration.between (instant, end);TenSystem.out.println ("This time:" +Duration.tomillis ()); One         //Local date no time and seconds ALocaldate localdate=Localdate.now ();
Temporalajusters Time Arithmetic -Localdate localdate1= Localdate.with (Temporaladjusters.dayofweekinmonth (2, Dayofweek.friday)); - System.out.println (localDate1); the //Custom Date Orthotics Use the Plus* method to make it easy to run time
- -Temporaladjuster Next_workday = W, {//Custom Corrector -Localdate resultdate =(Localdate) W; + Do { -Resultdate = resultdate.plusmonths (1). Plusdays (-1); +} while(Resultdate.getdayofweek (). GetValue () >= 6); A returnresultdate; at }; - -Localdate LocalDate2 =Localdate1.with (next_workday); -System.out.println ("Next month's time" +localDate2); - //time format, the key is local time!! With sometimes a few seconds. -LocalDateTime LocalDateTime =Localdatetime.now (); inSystem.out.println ("Time Type:" +datetimeformatter.oflocalizeddatetime (formatstyle.medium). Format ( -LocalDateTime));//language-dependent format time format conversion also package is better. to +System.out.println ("Time Type:" +datetimeformatter.ofpattern ("Yyyy/mm/dd hh"). Format ( -LocalDateTime));

Changes in time and data in Java8

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.