Java Date Classes

Source: Internet
Author: User

The main change in the Java 8 date time API was that date and time are now no. longer represented by a single number of Milli seconds since Jan. 1st 1970, but by the number of seconds and nanoseconds since Jan. 1st 1970. The number of seconds can be both positive and negative and are represented by a long . The number of nanoseconds is always positive and was represented by an int . You'll see this new date and time representation in many of the classes in the new Java date Time API.

The package java.time also contains a set of subpackages which contain more utilities etc. java.time.chronoFor instance the contains classes to work with Japanese, Thai, Taiwanese and Islamic calendars. The package java.time.format contains classes used-to-parse and format dates from and to strings.

The core of the Java 8 date time API consists of the following classes:

Instant Represents an instant in time on the time line. In the Java 7 date time API an instant is typically represented by a number of millseconds since Jan. 1st. 1970. In Java 8, the class represents an instant in time represented by a number of seconds and a number of Instant nanoseconds sin Ce Jan. 1st 1970.
Duration Represents a duration of time, for instance the time between the instants. Like the Instant Class A represents its time as a number of Duration seconds and nanoseconds.
LocalDate Represents a date without time zone information-e.g. A birthday, official holiday etc.
LocalDateTime Represents a date and time without time zone information
LocalTime Represents a local time of day without time zone information.
TemporalAdjuster
ZonedDateTime Represents a date and time including time zone information
Period
DateTimeFormatter Formats Date Time objects as Strings. For instance a ZonedDateTime or a LocalDateTime .

Java 7 Date Time API

Java 7 has the following date and time classes and methods. Each of these classes is also explained in their own pages, later. See the links at the bottom for this page, or at the top right of every page.

System.currentTimeMillis() A static method that returns the current date and time as milliseconds since January 1st 1970
java.util.Date A class that represents a date and time. Most methods in this class is deprecated.
java.sql.Date A class that represents a date. All time information cut off. This date, class is used with JDBC.
java.sql.Timestamp A class that represents a date and time. This date and time class are used with JDBC.
java.util.Calendar A base class for calendar classes. Have methods to does date and time arithmethics like adding a day or month to another date.
java.util.GregorianCalendar A Concrete Class subclassing Java.util.Calendar, representing the Gregorian Calendar which is used in the very most of the Western World today. Have all the methods from Java.util.Calendar to do date and time arithmethics.
java.util.TimeZone The Java TimeZone class is a class this represents time zones, and is helpful when doing calendar arithmetics across time Zones.
java.text.SimpleDateFormat A class that can help you parse string's into Date ' s, and format date ' s as String ' s.

Java Date Classes

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.