Home Java Javadate Second Format Example

Related Tutorials


 
 

Share on Google+Share on Google+

Second Format Example

Advertisement
This example shows how to format second using Format class. In this program we use a pattern of special characters to time format.

Second Format Example

     

This example shows how to format second using Format class. In this program we use a pattern of special characters to time format.

Description of the code :

SimpleDateFormat() : SimpleDateFormat class use for formatting and parsing dates. It allows for formatting date into text , parsing text into date and normalization.

format() : This method used for format Date class object into date / time and appends the it into the StringBuffer.

SecondFormat.java

import java.text.*;
import java.util.*;

public class SecondFormat {

  public static void main(String args[]) {

  String s;
  Format formatter;
  Date date = new Date();

  formatter = new SimpleDateFormat("s")// 3
  s = formatter.format(date);
  System.out.println("Seconds : " + s);

  formatter = new SimpleDateFormat("ss");  // 03
  s = formatter.format(date);
  System.out.println("Seconds : " + s);
  }
}


Output:

Seconds : 1
Seconds : 01

Download code
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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: October 13, 2008

Related Tutorials

Discuss: Second Format Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
jero
August 24, 2011
Format

Second Format
DMCA.com