Jump to content

Recommended Posts

Posted

<textarea rows="49" cols="106" name="dateformat_yymmHHDD">import java.io.Serializable;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;



/**

* Working with dates is more complicated but this example will tell us more information on

* how to work on different date formats

*/



/**

* @author Darur Venugopal

* Retrieving date in required format like

*/

public class Date_Format_Java_yyyymmddhhmm  extends Date implements Serializable{

//Defin format

private final static DateFormat yyyymmdd = new SimpleDateFormat(&quot;yyyyMMdd &quot;);



//define Format

private final static DateFormat yyyymmddhhMMss = new SimpleDateFormat(&quot;yyyyMMddHHmmss&quot;);



//process and return required format

public String getdateFormatmmddyyyy() {

return yyyymmdd.format(this);

}



/**

* @param args

*/

public static void main(String[] args) {

//Step no 1 initialize some date

// retrieve in different format

DateFormatDemo dateFormats = new DateFormatDemo();

try

{

dateFormats.setTime(yyyymmddhhMMss.parse(&quot;20090206105100&quot;).getTime());

} catch (ParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//retrieve in HHmmss format

System.out.println( dateFormats.getHHmmssString());

//retrieve in yyyymmddformat

Date_Format_Java_yyyymmddhhmm format = new Date_Format_Java_yyyymmddhhmm();

System.out.println(format.getdateFormatmmddyyyy());

}



}

</textarea>

×
×
  • Create New...