Java Hour Format formatCurrentTime()

Here you can find the source of formatCurrentTime()

Description

format Current Time

License

Apache License

Return

the current date and time in RFC-1123 format (e.g. "Sun, 06 Nov 1994 08:49:37 GMT")

Declaration

public static String formatCurrentTime() 

Method Source Code


//package com.java2s;
/*//w  w  w.j  a  va2 s  .c o  m
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2014 wcm.io
 * %%
 * 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.
 * #L%
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    private static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
    private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone("GMT");

    /**
     * @return the current date and time in RFC-1123 format (e.g. "Sun, 06 Nov 1994 08:49:37 GMT")
     */
    public static String formatCurrentTime() {
        return getDateFormat().format(new Date());
    }

    private static DateFormat getDateFormat() {
        SimpleDateFormat df = new SimpleDateFormat(PATTERN_RFC1123, Locale.US);
        df.setTimeZone(GMT_TIME_ZONE);
        return df;
    }
}

Related

  1. formatCalTime(Date time)
  2. formatCapDate(Calendar cal)
  3. formatCompleteDate(Date date)
  4. formatCreationDate(String creationDate)
  5. formatCurrentDateForDebug()
  6. formatCurrentTime()
  7. formatCurrentTime(final String format)
  8. formatDate(Calendar currentDate, String pattern)
  9. formatDate(Calendar time)