To set the time zone programmatically, you need to use the date class. See His reference documents here .
You need to use the setTimeZone()
method of the SimpleDateFormat
class.
The following is an example code for setting the time zone according to America
// First Create Object of Calendar Class Calendar calendar = Calendar.getInstance(); // Now Set the Date using DateFormat Class SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss z"); // Finally Set the time zone using SimpleDateFormat Class setTimeZone() Method sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
source share