Java api ---- Date class, javaapi ---- date class

Source: Internet
Author: User

Java api ---- Date class, javaapi ---- date class

The Date class in the java. util package represents a specific time, accurate to milliseconds. The Date class provides two constructors to instantiate the Date object.

The first constructor uses the current Date and time to initialize the object Date ();

The second constructor uses the number of milliseconds since January 1, January 1, 1970 as the parameter Date (long millisec );

import java.util.Date;public class GetDate{    public static void main(String args[]){        Date now=new Date();        System.out.println(now);        System.out.println(now.toString());    }}

 

import java.util.Date;public class SetDate{    public static void main(String args[]){        Date Set=new Date(151516);        System.out.println(Set);        System.out.println(Set.toString());    }}

 

You can use SimpleDateFormat to set the date output format:

import java.util.*;import java.text.SimpleDateFormat;public class DateFormat{   public static void main(String args[]) {      Date dNow = new Date( );      SimpleDateFormat ft =       new SimpleDateFormat (" yyyy.MM.dd 'at' hh:mm:ss a");      System.out.println("Current Date: " + ft.format(dNow));   }}

 

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.