skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Friday, October 12, 2012

To display System date and time

Posted by Raju Gupta at 1:34 PM – 0 comments
 

This Program will helps to know the current system date and time.


import java.util.*;

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

  Calendar cl=Calendar.getInstance();

  //display date separately
  System.out.print("Current date: ");
  int dd=cl.get(Calendar.DATE);
  int mm=cl.get(Calendar.MONTH);
  ++mm;
  int yy=cl.get(Calendar.YEAR);
  System.out.println(dd+ "-" + mm + "-" +yy);

  //display time alone

  System.out.print("Current time: ");
  int h=cl.get(Calendar.HOUR);
  int m=cl.get(Calendar.MINUTE);
  int s=cl.get(Calendar.SECOND);
  System.out.println(h+ ";" + m + ";" +s);

  int x=cl.get(Calendar.AM_PM);
  if(x==0) System.out.println("Good Morning");
  else System.out.println("Good Evening");

 }

}



Labels: Java Date and Time Example , Java DateFormat Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger