Java Date Calculate calculateTime(Date sendTime, String timeZoneID)

Here you can find the source of calculateTime(Date sendTime, String timeZoneID)

Description

calculate Time

License

Open Source License

Declaration

public static String calculateTime(Date sendTime, String timeZoneID) 

Method Source Code

//package com.java2s;
/**/*from w  ww.  ja  v a2  s  .  c  o m*/
 * JHylaFax - A java client for HylaFAX.
 *
 * Copyright (C) 2005 by Steffen Pingel <steffenp@gmx.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

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

import java.util.TimeZone;

public class Main {
    public static String calculateTime(Date sendTime, String timeZoneID) {
        if (sendTime == null) {
            return "NOW";
        } else {
            long date = sendTime.getTime();

            TimeZone tz = TimeZone.getTimeZone(timeZoneID);
            //         tz.setStartRule(Calendar.MARCH, -1, Calendar.SUNDAY,  2*60*60*1000);
            //         tz.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY,  2*60*60*1000);

            date -= tz.getRawOffset();
            if (tz.inDaylightTime(sendTime)) {
                date -= 3600 * 1000;
            }

            return new SimpleDateFormat("yyyyMMddHHmm").format(new Date(
                    date));
        }
    }
}

Related

  1. calculateMonthIn(Date date1, Date date2)
  2. calculateNextSettleDate(Date date, int addMonth)
  3. calculateOffsetFromGMT(Date date)
  4. calculatePastDate(int days)
  5. calculateTime(Date date, String addpart, int num)
  6. calculateTimestamp()
  7. calculateTruncatedTime(final Date dateTimeBegin, final Date dateTimeEnd, final Date begin, final Date end)
  8. calculateTruncatedTimeByDays( final Date dateTimeStart, final Date dateTimeEnd, final Date start, final Date end)
  9. calculationAge(Date birthday, Date calculateDay)