Java Date Now getCurrentUTCString()

Here you can find the source of getCurrentUTCString()

Description

Get current date in yyyy-dddThh:mm:ss.sss format (GMT)

License

Open Source License

Return

current date string

Declaration

public static String getCurrentUTCString() 

Method Source Code

//package com.java2s;
/*//from   w ww  .  j  a  v a  2s  .  c o m
 * License information at https://github.com/Caltech-IPAC/firefly/blob/master/License.txt
 */

import java.text.NumberFormat;

import java.util.Calendar;
import java.util.GregorianCalendar;

import java.util.TimeZone;

public class Main {
    /**
     *  Get current date in yyyy-dddThh:mm:ss.sss format (GMT)
     *  @return current date string
     */
    public static String getCurrentUTCString() {
        NumberFormat i3 = NumberFormat.getInstance();
        NumberFormat i2 = NumberFormat.getInstance();
        i3.setMinimumIntegerDigits(3);
        i2.setMinimumIntegerDigits(2);
        Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        String date = cal.get(Calendar.YEAR) + "-"
                + i3.format(cal.get(Calendar.DAY_OF_YEAR)) + "T"
                + i2.format(cal.get(Calendar.HOUR_OF_DAY)) + ":"
                + i2.format(cal.get(Calendar.MINUTE)) + ":"
                + i2.format(cal.get(Calendar.SECOND)) + "."
                + i3.format(cal.get(Calendar.MILLISECOND));
        return date;
    }
}

Related

  1. getCurrentToNextDaySecond()
  2. getCurrentUnixTime()
  3. getCurrentUTCDate()
  4. getCurrentUtcDate()
  5. getCurrentUTCSeconds(Date current)
  6. getCurrentUTCTime()
  7. getCurrentUTCTimeAsString()
  8. getCurrentWeekDay(Date date, int day)
  9. getCurrentWeekDays()