10-30-2009 06:55 AM
Ok Thanks a lot for the clarifications...
10-30-2009 07:48 AM
Is this solved then?
Would it be possible to post the code that you are using to output the Time Zone Offset (Z)?
10-30-2009 09:34 AM - edited 10-30-2009 09:46 AM
OK.
TimeZone _timeZone = TimeZone.getDefault(); // Asia/Calcutta
boolean isDayLightSavings = _timeZone.useDaylightTime();
Calendar _calendar = Calendar.getInstance();
int gmtOffset = _timeZone.getOffset(1, _calendar.get(Calendar.YEAR), _calendar.get(Calendar.MONTH), _calendar.get(Calendar.DATE), _calendar.get(Calendar.DAY_OF_WEEK), _calendar.get(Calendar.MILLISECOND));
int gmtOffset_Hr = gmtOffset_Milisec/DateTimeUtilities.ONEHOUR;
int gmtOffset_Min = (gmtOffset_Milisec % DateTimeUtilities.ONEHOUR)/DateTimeUtilities.ONEMINUTE;
Then I gets gmtOffset_Hr = 5 & gmtOffset_Min = 30. Then after using Strign methods on it I gets it as +05 & 30 and put it in
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss "+gmtOffset_HH.trim()+gmtOffset_MM.trim());
Date date = new Date();
date.setTime(System.currentTimeMillis());
String formattedDate = dateFormat.format(date).toString();
Thanks for the suggestions... got it ? let me know if any problem.
10-30-2009 10:23 AM
Happy with the first block of you code. Be aware that
boolean isDayLightSavings = _timeZone.useDaylightTime();
only tells you if the Time Zone uses Daylight Saving, not whether it is currently in a Daylight Saving period.
Not sure that your second block actually compiles? This doesn't look right:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss "+gmtOffset_HH.trim()+gmtOffset_MM.trim());
10-31-2009 12:34 AM
but
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss "+gmtOffset_HH.trim()+gmtOffset_MM.trim());
gives me correct time as "currenttime +0530"
10-31-2009 06:36 AM - edited 10-31-2009 06:37 AM
Ahh I see.
You realize that you are passing in the String as a parameter to your SimpleDateFormat, which it then thinks is a constant and so does not do substitution.
It would normally have been written as follows, which I am happy with:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
Date date = new Date();
date.setTime(System.currentTimeMillis());
String formattedDate = dateFormat.format(date).toString() +gmtOffset_HH.trim()+gmtOffset_MM.trim();
10-31-2009 10:12 AM
Hey thanks. Its working with ur code.. Thanks a lot....
10-31-2009 10:29 AM
Can we mark this as Solved then?
10-31-2009 10:48 AM
I have marked it as solved.
Thansk a lot for the help...
04-16-2012 06:43 AM
what is
gmtOffset_Milisec