Android Long to Date Convert toIso8601(long date, boolean utc)

Here you can find the source of toIso8601(long date, boolean utc)

Description

Formats a date / time according to the ISO 8601 format, optionally forcing to UTC.

License

Apache License

Parameter

Parameter Description
date The date / time to format.
utc If true , the resulting string will be in UTC timezone (that is, ending with "Z").

Return

The formatted date / time.

Declaration

public static synchronized String toIso8601(long date, boolean utc) 

Method Source Code

//package com.java2s;
/*/* w w w.j  a v a 2  s .  co  m*/
 * This source is part of the
 *      _____  ___   ____
 *  __ / / _ \/ _ | / __/___  _______ _
 * / // / , _/ __ |/ _/_/ _ \/ __/ _ `/
 * \___/_/|_/_/ |_/_/ (_)___/_/  \_, /
 *                              /___/
 * repository.
 *
 * Copyright (C) 2013 Benoit 'BoD' Lubek (BoD@JRAF.org)
 * Copyright (C) 2009 The Android Open Source Project
 *
 * 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.SimpleDateFormat;

import java.util.Locale;

public class Main {
    private static SimpleDateFormat DATE_FORMAT_ISO8601 = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
    private static SimpleDateFormat DATE_FORMAT_ISO8601_UTC = new SimpleDateFormat(
            "yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);

    /**
     * Formats a date / time according to the ISO 8601 format, optionally forcing to UTC.
     * 
     * @param date The date / time to format.
     * @param utc If {@code true}, the resulting string will be in UTC timezone (that is, ending with "Z").
     * @return The formatted date / time.
     */
    public static synchronized String toIso8601(long date, boolean utc) {
        if (utc) {
            return DATE_FORMAT_ISO8601_UTC.format(date);
        }
        return DATE_FORMAT_ISO8601.format(date);
    }
}

Related

  1. timestampToIso8601Str(long timestamp)
  2. timestampToIso8601Str(long timestamp)
  3. toCalendar(long hour)
  4. toDateString(long seconds)
  5. toFullDate(long timestamp)
  6. toJulianDay(long epochMillis)
  7. toJulianDayNumber(long epochMillis)
  8. toString(Long datetime)
  9. toTimeString(long milliseconds)