Java SQL Date Convert to2GMTString(final Date tsStart, final Date tsEnd)

Here you can find the source of to2GMTString(final Date tsStart, final Date tsEnd)

Description

to GMT String

License

Open Source License

Declaration

public static String to2GMTString(final Date tsStart, final Date tsEnd) 

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";

    /**/*from  w  ww  .  j a v  a2 s.  co  m*/
     * 
     * @param tsStart
     * @param tsEnd
     * @return
     *
     * @author Anton Nedbailo
     * @date Sep 29, 2013
     */
    public static String to2GMTString(final Timestamp tsStart, final Timestamp tsEnd) {
        return timestampToString(tsStart, STANDARD_DATETIMEFORMAT, TZ_UTC) + " - "
                + timestampToString(tsEnd, STANDARD_DATETIMEFORMAT, TZ_UTC) + " GMT";
    }

    public static String to2GMTString(final Date tsStart, final Date tsEnd) {
        return timestampToString(new Timestamp(tsStart.getTime()), STANDARD_DATETIMEFORMAT, TZ_UTC) + " - "
                + timestampToString(new Timestamp(tsEnd.getTime()), STANDARD_DATETIMEFORMAT, TZ_UTC) + " GMT";
    }

    /**
     * 
     * @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. dateToString(Date date, String format)
  2. dateToString(java.sql.Date d)
  3. dateToString(java.sql.Date data)
  4. dateToString(java.sql.Date datee)
  5. dateToString(java.util.Date date, String dateFmt)
  6. to_char(Date date, String format)
  7. to_char(Date date, String format)
  8. toBigDecimal(@Nullable final Date value)
  9. toCalender(final Date aDate)