Advertisement
steverobinson

CurrentDateXtract

Jul 24th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.util.Date;
  2.  
  3.  
  4. @SuppressWarnings( "deprecation" )  //Date API was deprecated. But its safe to use it for small apps...
  5. class DateDemo
  6. {
  7.     public static void main(String arg[])
  8.     {
  9.         Date currentDate=new Date();            //Assigns Current Date to DateObject
  10.        
  11.         int date,month,year,minutes,hours;
  12.        
  13.        
  14.         //You can use below variables to initialize object of your custom Date class with Current Date!
  15.        
  16.         date=currentDate.getDate();             //get Date from currentDate
  17.         month=currentDate.getMonth()+1;         //get Month (starts with 0) from currentDate
  18.         year=currentDate.getYear()+1900;        //get Year (from year 1900) from currentDate
  19.         minutes=currentDate.getMinutes();       //get Minutes from currentDate
  20.         hours=currentDate.getHours();           //get Hours from currentDate
  21.            
  22.        
  23.         System.out.println("Current Date: \n"+ date+"-"+month+"-"+year+"  "+hours+":"+minutes);
  24.        
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement