Java Date Create toDateHeader(long value)

Here you can find the source of toDateHeader(long value)

Description

to Date Header

License

Open Source License

Declaration

public static String toDateHeader(long value) 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.text.SimpleDateFormat;

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

public class Main {
    /**//w  w w  .  j a v  a2  s  . co m
     * Per thread pre-initialized date formatters
     */
    private static final ThreadLocal<SimpleDateFormat[]> DATE_FORMATS = new ThreadLocal<SimpleDateFormat[]>() {
        @Override
        protected synchronized SimpleDateFormat[] initialValue() {
            SimpleDateFormat[] fmts = new SimpleDateFormat[] {
                    // The first two formats are the same because we use fmts[0] for
                    // parsing and fmts[1] for formatting. We uses separate objects for
                    // these tasks because parsing a date actually modifies the
                    // timezone that the formatting object uses for formatting.
                    new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
                    new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
                    new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
                    new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US) };
            fmts[0].setTimeZone(TimeZone.getTimeZone("GMT"));
            fmts[1].setTimeZone(TimeZone.getTimeZone("GMT"));
            fmts[2].setTimeZone(TimeZone.getTimeZone("GMT"));
            fmts[3].setTimeZone(TimeZone.getTimeZone("GMT"));
            return fmts;
        }
    };

    public static String toDateHeader(long value) {
        final SimpleDateFormat[] formats = DATE_FORMATS.get();
        return formats[0].format(new Date(value));
    }
}

Related

  1. ToDate(Object o)
  2. toDate(Object object)
  3. toDate(Object value)
  4. toDateFormat(Date date)
  5. toDateFromLong(Long time)
  6. toDateList(Collection list)
  7. toDateQueryFormat(Date value)
  8. toDateStr(Date d)
  9. ToDateStr(Date dt)