Friday, July 31, 2009

get the System Date Time Blackberry

Date d = new Date(System.currentTimeMillis());
lblDate = new LabelField(d.toString());

this will return Long Date Including timizone and all the things. but if you want a format the date time to shor, long or medium you can use following method.

Medium Date

SimpleDateFormat df = new SimpleDateFormat(SimpleDateFormat.DATE_MEDIUM); 
 String Mydate = df.format(new Date(System.currentTimeMillis()));
Ex:-Mar 08, 2006.

Short Date

SimpleDateFormat df = new SimpleDateFormat(SimpleDateFormat.DATE_SHORT); 
String Mydate = df.format(new Date(System.currentTimeMillis()));
Ex:-03.08.06.

Long Date

SimpleDateFormat df = new SimpleDateFormat(SimpleDateFormat.DATE_LONG); 
String Mydate = df.format(new Date(System.currentTimeMillis()));
Ex:-Wednesday, March 08, 2006.

Custom Date

SimpleDateFormat df = new SimpleDateFormat("MMMM, dd yyyy"); 
String Mydate = df.format(new Date(System.currentTimeMillis()));
Ex:-March 08, 2006.

Some Formating Examples

"yyyy.MM.dd G 'at' HH:mm:ss z" ------>  2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy" ------------------> Wed, Jul 4, '01
"h:mm a" ----------------------------> 12:08 PM
"hh 'o''clock' a, zzzz" ------------->  12 o'clock PM, Pacific Daylight Time
"K:mm a, z" ------------------------->  0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa" ------> 02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z" -------->  Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ" ---------------------> 010704120856-0700                   
Post a Comment