Java examples for java.util:Calendar Calculation
Gets the calendar at given time at GMT
/* Penny Post - A postage system for email * Copyright (c) 2006-2007 Gregory Rubin <grrubin@gmail.com> * http://www.nettgryppa.com //from w w w .j ava 2 s. c o m * Copyright (C) 2007 Aliasgar Lokhandwala <d7@freepgs.com> * http://pennypost.sourceforge.net/ * * CashUtils.java: Provides common helper methods * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ //package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; public class Main { public static void main(String[] argv) throws Exception { String sTime = "java2s.com"; System.out.println(getGMTCalendarAtTime(sTime)); } /** * Date format string */ public static final String m_sDtFormat = "yyMMdd"; /** * Gets the calendar at given time at GMT * @author Ali */ public static Calendar getGMTCalendarAtTime(String sTime) throws ParseException { SimpleDateFormat dtFormat = new SimpleDateFormat(m_sDtFormat); Calendar newDate = getGMTCalendar(); newDate.setTime(dtFormat.parse(sTime)); return newDate; } /** * Gets the calendar at current time at GMT * @author Ali */ public static Calendar getGMTCalendar() { return Calendar.getInstance(TimeZone.getTimeZone("GMT")); } }