Java tutorial
//package com.java2s; /* * Copyright 2015 Yan Zhenjie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { /** * Format of http head. */ public static final String FORMAT_HTTP_DATA = "EEE, dd MMM y HH:mm:ss 'GMT'"; /** * Commmon TimeZone for GMT. */ public static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone("GMT"); /** * Parsing the TimeZone of time in milliseconds. * * @param gmtTime GRM Time, Format such as: {@value #FORMAT_HTTP_DATA}. * @return The number of milliseconds from 1970.1.1. * @throws ParseException if an error occurs during parsing. */ public static long parseGMTToMillis(String gmtTime) throws ParseException { SimpleDateFormat formatter = new SimpleDateFormat(FORMAT_HTTP_DATA, Locale.US); formatter.setTimeZone(GMT_TIME_ZONE); Date date = formatter.parse(gmtTime); return date.getTime(); } }