Here you can find the source of to2GMTString(final Date tsStart, final Date tsEnd)
public static String to2GMTString(final Date tsStart, final Date tsEnd)
//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); } }