Here you can find the source of toUTC(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static Date toUTC(Date date)
//package com.java2s; /**/* w w w .j a v a2 s . c om*/ * Copyright (C) 2015 https://github.com/ymanv * * This software is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /** * Extract date and time from the given date and returns a date object with * the same date/time on the UTC time zone. * * @param date */ public static Date toUTC(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); Calendar utcCal = Calendar.getInstance(); utcCal.setTimeZone(TimeZone.getTimeZone("UTC")); utcCal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)); utcCal.set(Calendar.MILLISECOND, cal.get(Calendar.MILLISECOND)); return utcCal.getTime(); } }