Friday, July 19, 2013

PROGRAM USING DATE CLASS

Date class links:CLICK HERE

Date formatting Links: CLICK HERE

Example Program:
~~~~~~~~~~~~
import java.util.*;
import java.text.*;

public class DateDemo {
public static void main(String args[]) {

Date dNow = new Date( );
SimpleDateFormat ft = 
new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");

System.out.println("Current Date: " + ft.format(dNow));
}
}

OUTPUT:
~~~~~
Current Date: Fri 2013.07.19 at 11:07:24 PM IST

EXPLANATION:
~~~~~~~~~
E ->indicates Day in a week.

y ->indicates Year in four digits

M ->indicates Month of the year

h ->Hour of a day(12 hrs)

H -> Hour of a day(24 hrs)

a ->am or pm

s ->seconds

z ->timezone

No comments:

Post a Comment

Animated Social Gadget - Blogger And Wordpress Tips