Convert date to long

Source: Internet
Author: User

In this section you will learn to convert the date into a long format.
Java. util
Package provides the functionality to convert a date type into a long type.

Description of program:

The following program helps you in converting a date into a long type. First of all you need a date that needs to be converted.
DateformatIs a constructor to create a new date format.
Gettime ()
Method is used to convert the given date into a long type.
This method returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date object. Which is of long type.

 

 Here is the code of program:

 

import java.util.*;import java.text.*;public class DateToLong {  public static void main(String[] args) {  try {  String str_date="11-June-07";  DateFormat formatter ;   Date date ;   formatter = new SimpleDateFormat("dd-MMM-yy");  date = (Date)formatter.parse(str_date);   long longDate=date.getTime();  System.out.println("Today is " +longDate );  }  catch (ParseException e){  System.out.println("Exception :"+e);   }  }} 

 

 

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.