Java8 Date/time (date) Usage Introduction

Source: Internet
Author: User

Special Note : LocalDateTime for the calculation of the date and time provides a great convenience, in the construction of object/operation/tostring, such as convenience are very convenient.

3 Common Classes :

Java.time.localdatetime;java.time.localdate;java.time.localtime;

Recommended Multi-use LocalDateTime

Common Expressions :
Present: LocalDateTime now = Localdatetime.now ();
Today: localdate day = Localdate.now ();

To create an object from a property :
localdatetime.of (int year, month month, int dayofmonth, int hour, int minute, C6>int Second, int nanoofsecond)

convert each other :

Localdate date == = = = Localdatetime.of (date.getyear () + 1900, Date.getmonth () + 1  New// will lose Nanoofsecond

Component Compatibility :

    • MyBatis (mybatis-spring v1.3.0) is not currently supported LocalDateTime
    • Json (Com.fasterxml.jackson.core v2.5.4) seems to have no special support, the result of serialization is as follows:
{  "month": "December",  "year":,  "DayOfMonth": 7,  " DayOfWeek ":" Thursday ",  " dayofyear ": 341,  " Monthvalue ":"  Hour ": Ten,  "minute": 4,  "nano": 228000000,  "second":  "Chronology": {    "id": "ISO",    "CalendarType": "iso8601"  }}

Therefore, when interacting with the database, it is recommended to use java.util.Date when interacting with the Json

Summary :
In the current case, business calculations suggest using LocalDateTime, which is recommended for conversion to Date outside of business calculations

by the To:
LocalDateTime is a great convenience for the calculation of date and time, and there are many other advantages. Details Java8 (date time) API Guide] (http://www.importnew.com/14140.html

Java8 Date/time (date) Usage Introduction

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.