Home Java Java-conversion Convert Long to Date
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Convert Long to Date

Advertisement
In this section, you will learn to convert a long into a date format. Java provides some methods and APIs to solved it.

Convert Long to Date

     

In this section, you will learn to convert a long into a date format. Java provides some methods and APIs to solved it. 

Description of program:

This example helps you in converting a  long value into a Date. The getDateInstance() method is a time formatter with the given formatting style for the default locale. And the getTimeInstance(int style) method is used to get the time formatter with the given formatting style for the default locale. Here style gives the formatting style.

Some other styles are:

  1. FULL
  2. LONG
  3. MEDIUM
  4. SHORT
  5. DEFAULT

[Note: Its value is MEDIUM.]

 

Here is the code of program:

import java.util.*;
import java.text.*;
public class LongToDate {
 public static void main(String[] args)throws Exception {
  Date date = new Date();
  DateFormat dataformat =  DateFormat.
getDateInstance(DateFormat.LONG);
 
  String s4 = dataformat.format(date);
 System.out.println(dataformat.format(date));  
  } }  

Output of this program:

C:\date>javac LongToDate.java
C:\date>java LongToDate
June 12, 2007

Download this example.

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2007

Ask Questions?    Discuss: Convert Long to Date   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com