Date using Java: create Data using year, month, day, hour, minute, seconds in Java

Creating  custom date using java
1) Using java.util.Date
 int year=2013;
int month=5;   // months starts from 0 to 11, as 0 stands January and 11 stands for December
int day=15;
int hour=12;
int minute=58;
int seconds=47;

*** Date utilDateObj=new Date(year,month,day,hour,minute,seconds);

***  This is depricated.

We recommend to use Calander as given below:
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.YEAR, year);

calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, seconds);

Date lastUpdatedDate = calendar.getTime();

Comments

Popular posts from this blog

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

Upload csv file at Google Cloud Storage using java

Read Images from a xlsx file using Apache POI