Java Date Now getCurrentTimeStamp()

Here you can find the source of getCurrentTimeStamp()

Description

Description - method to get current time stamp in GMT

License

Open Source License

Return

timeAsString

Declaration


public static String getCurrentTimeStamp() 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static final String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String GMT_TIME_ZONE = "GMT";

    /**/* w ww.j  a  v  a  2s .  c om*/
     * Description - method to get current time stamp in GMT
     * @return timeAsString
     */

    public static String getCurrentTimeStamp() {

        // set the date format to standard format
        SimpleDateFormat dateFormat = new SimpleDateFormat(TIME_FORMAT);
        // set GMT time zone
        dateFormat.setTimeZone(TimeZone.getTimeZone(GMT_TIME_ZONE));
        // create a date object
        Date date = new Date();
        // return the current time stamp
        return dateFormat.format(date);

    }
}

Related

  1. getCurrentTimestamp()
  2. getCurrentTimeStamp()
  3. getCurrentTimestamp()
  4. getCurrentTimeStamp()
  5. getCurrentTimestamp()
  6. getCurrentTimestampAsISOString()
  7. getCurrentTimestampString()
  8. getCurrentTimeStr()
  9. getCurrentTimeStr()