Java SQL Date Convert toGMT(final Date ts)

Here you can find the source of toGMT(final Date ts)

Description

to GMT

License

Open Source License

Parameter

Parameter Description
ts time

Return

Wandelt einen Timestamp in eine String bezogen auf GMT um.

Declaration

public static String toGMT(final Date ts) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;

import java.text.SimpleDateFormat;

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

public class Main {
    public static final String STANDARD_DATETIMEFORMAT = "dd.MM.yyyy HH:mm";
    public static final String TZ_UTC = "UTC";

    /**// ww  w.j av  a 2  s  .  c o  m
     * @param ts time
     * @return Wandelt einen Timestamp in eine String bezogen auf GMT um.
     * 
     */
    public static String toGMT(final long ts) {
        return toGMT(new Timestamp(ts));
    }

    /**
     * @param ts time
     * @return Wandelt einen Timestamp in eine String bezogen auf GMT um.
     * 
     */
    public static String toGMT(final Date ts) {
        return timestampToString(ts, STANDARD_DATETIMEFORMAT, TZ_UTC);
    }

    /**
     * 
     * @param ts
     * @param format
     * @param tzId
     * @return
     *
     * @author Anton Nedbailo
     * @date Sep 29, 2013
     */
    public static String timestampToString(final Date ts, final String format, final String tzId) {
        Date ret = ts;
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        formatter.setTimeZone(TimeZone.getTimeZone(tzId));
        if (ret == null) {
            ret = new Date();
        }
        return formatter.format(ret);
    }
}

Related

  1. toBigDecimal(@Nullable final Date value)
  2. toCalender(final Date aDate)
  3. todaySqlDate()
  4. toDBDate(String str)
  5. toEnglishDate(String stringDate)
  6. toInt(java.util.Date v)
  7. toIntDate(Object object, int iDefault)
  8. toJavaDate(java.sql.Date date)
  9. toJavaDate(java.sql.Date sqlDate)