Java Timestamp Format Timestamp2UTC(Timestamp mytime)

Here you can find the source of Timestamp2UTC(Timestamp mytime)

Description

Converts a java.util.Timestamp to UTC needed if the "Generalized Time Syntax Plug-in" of FedoraDS is not enabled

License

Open Source License

Parameter

Parameter Description
mytime input timestamp

Return

UTC SQL timestamp

Declaration

public static String Timestamp2UTC(Timestamp mytime) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import java.util.TimeZone;

public class Main {
    /**//from  w  w  w  .  j  ava  2 s.  c o m
     * Converts a java.util.Timestamp to UTC
     * needed if the "Generalized Time Syntax Plug-in" of FedoraDS is not enabled
     * @param mytime input timestamp
     * @return UTC SQL timestamp
     */
    public static String Timestamp2UTC(Timestamp mytime) {
        Timestamp b = new Timestamp(mytime.getTime());
        SimpleDateFormat mySimpleFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        mySimpleFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        String ret = mySimpleFormat.format(b) + "Z";

        return ret;
    }
}

Related

  1. TimeStamp2Date(long timestampString, String formats)
  2. timeStamp2Date(String seconds, String format)
  3. Timestamp2DDMMYYYY(java.sql.Timestamp ts)
  4. Timestamp2HHMMSS(java.sql.Timestamp ts, int iStyle)
  5. timestamp2String(long source, DateFormat format)
  6. timestampConvertToString(int timeStamp, String format)
  7. timeStampForFileName(final String simpleDateFormat)
  8. timestampFormat(Date date)
  9. timestampFormat(final Date date)