PDA

View Full Version : System time problem


swastik
8th April 2009, 01:42 PM
I have the following code to retrieve the current system time


public static String getCurrentTimeAsString() {
Calendar cal = Calendar.getInstance();
StringBuffer sBuf = new StringBuffer();
int month = cal.get(Calendar.MONTH) + 1;
sBuf.append(month);
sBuf.append("-");
sBuf.append(cal.get(Calendar.DATE));
sBuf.append("-");
sBuf.append(cal.get(Calendar.YEAR));
sBuf.append(" ");
sBuf.append(cal.get(Calendar.HOUR_OF_DAY));
sBuf.append(":");
sBuf.append(cal.get(Calendar.MINUTE));
sBuf.append(":");
sBuf.append(cal.get(Calendar.SECOND));

return sBuf.toString();
}


The code works fine on all devices except on windows mobile with Esmertec Jbed platform, where I am getting a completely wrong time.

Any help in this regard will be highly appreciated.

DaveShaw
8th April 2009, 03:09 PM
What's wrong with DateTime.Now.ToString(datetime format string) ?

Ta
Dave