Java8 local datetime API

Source: Internet
Author: User
Tags date1 time zones local time

localdate/local time and LocalDateTime class simplifies time zones without the need for development.

Let's take a look at their operation.

Choose to use any editor to create the following Java program in c:/> Java

Java8tester.java

Import java.time.localdate;import java.time.localtime;import java.time.localdatetime;import  java.time.month;public class java8tester {   public static void  main (string args[]) {      java8tester java8tester =  New java8tester ();       java8tester.testlocaldatetime ();     }   public void testlocaldatetime () {      //  get the current date and time      localdatetime  currenttime = localdatetime.now ();            system.out.println ("current datetime: "  + currenttime);       localdate date1 = currenttime.tolocaldate ();       System.out.println ("date1: " + date1");       month month = currenttime.getmonth ();       int day = currenttime.getdayofmonth ();       int seconds = currenttime.getsecond ();       System.out.println ("month: "  + month         + "Day :  " + day         +" seconds:  " +  seconds      );       localdatetime date2  = currenttime.withdayofmonth (withyear);       System.out.println ("date2: "  + date2);       //12 december  2014      localdate date3 = localdate.of (2014,  MONTH.DECEMBER, 12);       system.out.println ("date3: "  + date3);       // 22 hour 15 minutes      localtime date4 =  Localtime.of (22, 15);        system.out.println ("date4: "  +  DATE4);      //parse a string       localtime date5 = localtime.parse ("20:15:30");        System.out.println ("date5: "  + date5);    }}
Validation results

Click on the link to view the details

Java8 local datetime API

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.