Home Java Javadate Second Format Example



Second Format Example
Posted on: October 13, 2008 at 12:00 AM
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

Related Tags for Second Format Example:
cclassormformtimeformatcharpatternusingthischaractercharactersshowforexamplecteprogramtoramexamciwssheusepeiminrmasmclspecialspecmehowproxaxampsspatracishaimemplaractttssthshocondpleplprndonogro


More Tutorials from this section

Ask Questions?    Discuss: Second Format Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.