Java Date Convert convertLocalToGMT(int[] dateTime)

Here you can find the source of convertLocalToGMT(int[] dateTime)

Description

Use this method on values returned from a DateTimeSelector, if you want the selector to show local time but serialize to GMT.

License

Open Source License

Declaration

public static void convertLocalToGMT(int[] dateTime) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005, 2012 IBM Corporation and others.
 * 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://from   www.  j  av  a  2  s. co m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    protected static final int YEAR = 0;
    protected static final int MONTH = 1;
    protected static final int DAY = 2;
    protected static final int HOUR = 3;
    protected static final int MINUTE = 4;
    protected static final int SECOND = 5;

    /**
     * Use this method on values returned from a DateTimeSelector, if you want the
     * selector to show local time but serialize to GMT.
     */
    public static void convertLocalToGMT(int[] dateTime) {
        // convert local timezone to GMT.
        Calendar local = new GregorianCalendar();
        local.set(dateTime[YEAR], dateTime[MONTH], dateTime[DAY], dateTime[HOUR], dateTime[MINUTE],
                dateTime[SECOND]);
        Calendar GMTcal = new GregorianCalendar(TimeZone.getTimeZone("GMT+0")); //$NON-NLS-1$
        GMTcal.setTime(local.getTime());
        dateTime[YEAR] = GMTcal.get(Calendar.YEAR);
        dateTime[MONTH] = GMTcal.get(Calendar.MONTH);
        dateTime[DAY] = GMTcal.get(Calendar.DATE);
        dateTime[HOUR] = GMTcal.get(Calendar.HOUR_OF_DAY);
        dateTime[MINUTE] = GMTcal.get(Calendar.MINUTE);
        dateTime[SECOND] = GMTcal.get(Calendar.SECOND);
    }
}

Related

  1. convertInputDateToString(Date inputDate)
  2. convertInt2Date(int date)
  3. convertIntToDate(final int iDate)
  4. convertIntToDate(final int iDate, final StringBuilder verbatimDate)
  5. convertLocalDateToUTCDate(Date localDate)
  6. convertLocalToTimezone(Date original, String targetTimezoneId)
  7. convertsDateToGMTTimezone(Date date)
  8. convertSistemDependentDateToDesiredTimeZone(final Date sistemDependentDate, TimeZone desiredTimeZone)
  9. convertStringToDate(String date)