Java Date Format ISO nowISO8601()

Here you can find the source of nowISO8601()

Description

Get the current time formatted to ISO8601

License

Open Source License

Return

date string

Declaration

public static String nowISO8601() 

Method Source Code

//package com.java2s;
/*//from   w  w  w.j  av  a 2  s  . co  m
 * Copyright (c) 2016-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant 
 * of patent rights can be found in the PATENTS file in the same directory.
 */

import java.text.DateFormat;

import java.text.SimpleDateFormat;

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

public class Main {
    /**
     * Get the current time formatted to ISO8601
     * 
     * @return date string
     */
    public static String nowISO8601() {
        final TimeZone tz = TimeZone.getTimeZone("UTC");
        final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
        df.setTimeZone(tz);
        return df.format(new Date());
    }
}

Related

  1. isoTime(Date d)
  2. longToISODate(long longDate)
  3. makeDateISO8601(Date date)
  4. millisecondsToISO8601(long date)
  5. NowFormatISO()
  6. parseISODateFormat(String dateStr)
  7. parseIsoDateTime(final String isoDateString, final String dateFormat)
  8. timeToIso8601(long time, boolean includeTime)
  9. toBasicISO8601DateTime(Date value)