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();

Popular posts from this blog

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine

Session timeout interceptor in struts 2