Java Day Between stdNewDate(String tzDiff)

Here you can find the source of stdNewDate(String tzDiff)

Description

std New Date

License

Open Source License

Declaration

public static Date stdNewDate(String tzDiff) 

Method Source Code

//package com.java2s;
/*// www  . jav  a 2  s  .  c  o  m
 * Copyright (C) 2012  Krawler Information Systems Pvt Ltd
 * All rights reserved.
 * 
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

import java.util.Calendar;

import java.util.Date;
import java.util.GregorianCalendar;

import java.util.TimeZone;

public class Main {
    public static Date stdNewDate(String tzDiff) {
        Calendar cal = Calendar.getInstance();
        Calendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT" + tzDiff));
        try {
            Date dt = new Date();
            cal1.setTimeInMillis(dt.getTime());
            cal.set(Calendar.YEAR, cal1.get(Calendar.YEAR));
            cal.set(Calendar.MONTH, cal1.get(Calendar.MONTH));
            cal.set(Calendar.DAY_OF_MONTH, cal1.get(Calendar.DAY_OF_MONTH));
            cal.set(Calendar.HOUR_OF_DAY, cal1.get(Calendar.HOUR_OF_DAY));
            cal.set(Calendar.MINUTE, cal1.get(Calendar.MINUTE));
            cal.set(Calendar.SECOND, cal1.get(Calendar.SECOND));
            cal.set(Calendar.MILLISECOND, cal1.get(Calendar.MILLISECOND));
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return cal.getTime();
        }
    }
}

Related

  1. monthDiff(Date beginDate, Date endDate)
  2. monthDiff(Date from, Date to)
  3. monthDiff(Date fromDate, Date toDate)
  4. monthDifference(final Date a, final Date b)
  5. monthsDiff(final Date data1, final Date data2)
  6. substractDate(final Date date, final Integer different)
  7. timeDifferenceInSeconds(Date startDate, Date endDate)
  8. timeDifferenceWithCurrentTime(Date startTime)
  9. truncateDifferMonths(Date date)