Here you can find the source of getAdjustedDateTime(Date dt, TimeZone tz)
Date
object adjusted for the given timezone.
Parameter | Description |
---|---|
dt | The date to be adjusted. |
tz | The desired timezone. |
public static Date getAdjustedDateTime(Date dt, TimeZone tz)
//package com.java2s; /******************************************************************************* * Copyright (c) {2009,2011} {Software Design and Collaboration Laboratory (SDCL) * , University of California, Irvine}. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*ww w .j ava 2 s. c o m*/ * {Software Design and Collaboration Laboratory (SDCL) * , University of California, Irvine} * - initial API and implementation and/or initial documentation *******************************************************************************/ import java.text.DateFormat; import java.text.ParseException; import java.util.Date; import java.util.TimeZone; public class Main { /** * Returns a <code>Date</code> object adjusted for the given timezone. * * @param dt The date to be adjusted. * @param tz The desired timezone. * @return */ public static Date getAdjustedDateTime(Date dt, TimeZone tz) { Date result = null; DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); df.setTimeZone(tz); try { result = df.parse(df.format(dt)); } catch (ParseException e) { // The exception will never be thrown, since we are parsing the same // pattern set in the DateFormat object. } return result; } }