Java UTC Date nowInUTC()

Here you can find the source of nowInUTC()

Description

Get the current time in UTC

License

Open Source License

Return

The current time in UTC

Declaration

public static String nowInUTC() 

Method Source Code

//package com.java2s;
/**/*from  www .j  av  a2  s  .  c o m*/
  * Copyright (c) 2009 University of Rochester
  *
  * This program is free software; you can redistribute it and/or modify it under the terms of the MIT/X11 license. The text of the  
  * license can be found at http://www.opensource.org/licenses/mit-license.php and copy of the license can be found on the project
  * website http://www.extensiblecatalog.org/. 
  *
  */

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    /**
     * Get the current time in UTC
     * @return The current time in UTC
     */
    public static String nowInUTC() {
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        df.setTimeZone(TimeZone.getTimeZone("GMT"));
        return df.format(date);
    }
}

Related

  1. getUtcTimestamp()
  2. getUtcTimestamp()
  3. getUTCTimestamp(Date date)
  4. getUtcTimestampAsString(Date date)
  5. getUTCTimeString4Digits(Date date)
  6. nowUtc(String pattern)
  7. nowUTCString()
  8. SerializeUtc(Date dt)
  9. stringToUTC(String utc)