/* * Copyright (c) 2015, 2017 Cisco Systems, Inc. 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 */ package org.opendaylight.sfc.tacker.util; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class DateUtils { public static Date getUtcDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); TimeZone timeZone = calendar.getTimeZone(); int offset = timeZone.getRawOffset(); if (timeZone.inDaylightTime(new Date())) { offset = offset + timeZone.getDSTSavings(); } int offsetHrs = offset / 1000 / 60 / 60; int offsetMins = offset / 1000 / 60 % 60; calendar.add(Calendar.HOUR_OF_DAY, (-offsetHrs)); calendar.add(Calendar.MINUTE, (-offsetMins)); return calendar.getTime(); } public static Date addHours(Date date, int hours) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.HOUR, hours); // minus number would decrement the days return cal.getTime(); } }