Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.format(Calendar.getInstance().getTime(), result, new FieldPosition(0));
return result.toString();
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.format(Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime(), result, new FieldPosition(0));
return result.toString();
Calendar c = Calendar.getInstance();
TimeZone tz = c.getTimeZone();
Long ms = c.getTimeInMillis();
Date dt = new Date(ms-tz.getOffset(ms));
The java Date object has no concept of timezone. The issue is converting the Date either using SimpleDateFormat or Date.toString(). In this case, it uses the local timezone in order to translate the Date (which is nothing more than the number of milliseconds since January 1st 1970, UTC) into a formatted date string.
Your best bet is to write a custom code routine and modify the TalendDate.getDate() code. You will need to set the TimeZone in the Calendar instance. For example:
replace this part of the code:SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.format(Calendar.getInstance().getTime(), result, new FieldPosition(0));
return result.toString();
with this:SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.format(Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime(), result, new FieldPosition(0));
return result.toString();
The way I came up with to do this is: Calendar c = Calendar.getInstance();
TimeZone tz = c.getTimeZone();
Long ms = c.getTimeInMillis();
Date dt = new Date(ms-tz.getOffset(ms));