?? dateutil.java
字號:
/*
* $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/util/DateUtil.java,v 1.8 2004/06/01 13:25:40 skoehler Exp $
* $Author: skoehler $
* $Revision: 1.8 $
* $Date: 2004/06/01 13:25:40 $
*
* ====================================================================
*
* Copyright (C) 2002-2004 by MyVietnam.net
*
* 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 any later version.
*
* All copyright notices regarding MyVietnam and MyVietnam CoreLib
* MUST remain intact in the scripts and source code.
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Minh Nguyen minhnn@MyVietnam.net
* @author: Mai Nguyen mai.nh@MyVietnam.net
*/
package net.myvietnam.mvncore.util;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @todo: add config option to this class
*/
public final class DateUtil {
public static final int SECOND = 1000;
public static final int MINUTE = SECOND * 60;
public static final int HOUR = MINUTE * 60;
public static final int DAY = HOUR * 24;
public static final int WEEK = DAY * 7;
public static final int YEAR = DAY * 365; // or 366 ???
/**
* This is the time difference between GMT time and Vietnamese time
*/
public static final long GMT_VIETNAM_TIME_OFFSET = HOUR * 7;
/**
* This is the time difference between GMT time and SERVER time
*/
private static long SERVER_TIME_OFFSET = HOUR * (new DateOptions()).serverHourOffset;
private static DateFormat ddMMyyyyFormat = new SimpleDateFormat ("dd/MM/yyyy");
private static DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.DEFAULT);
private static DateFormat datetimeFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);
/**
* private constructor
*/
private DateUtil() {// prevent instantiation
}
public static synchronized String getDateDDMMYYYY(Date date) {
return ddMMyyyyFormat.format(date);
}
public static synchronized String formatDate(Date date) {
return dateFormat.format(date);
}
public static synchronized String formatDateTime(Date date) {
return datetimeFormat.format(date);
}
public static Timestamp getCurrentGMTTimestamp() {
return new Timestamp(System.currentTimeMillis() - SERVER_TIME_OFFSET);
}
public static void updateCurrentGMTTimestamp(Timestamp timeToUpdate) {
timeToUpdate.setTime(System.currentTimeMillis() - SERVER_TIME_OFFSET);
}
public static Date getVietnamDateFromGMTDate(Date date) {
return new Date(date.getTime() + GMT_VIETNAM_TIME_OFFSET);
}
public static Date convertGMTDate(Date gmtDate, int hourOffset) {
return new Date(gmtDate.getTime() + hourOffset*HOUR);
}
public static Timestamp convertGMTTimestamp(Timestamp gmtTimestamp, int hourOffset) {
return new Timestamp(gmtTimestamp.getTime() + hourOffset*HOUR);
}
public static Timestamp getCurrentGMTTimestampExpiredYear(int offsetYear) {
//return new Timestamp(System.currentTimeMillis() + offsetYear*(365*24*60*60*1000));
Calendar now = Calendar.getInstance();
now.add(Calendar.YEAR, offsetYear);
return new Timestamp(now.getTime().getTime());
}
public static Timestamp getCurrentGMTTimestampExpiredMonth(int offsetMonth) {
Calendar now = Calendar.getInstance();
now.add(Calendar.MONTH,offsetMonth);
return new Timestamp(now.getTime().getTime());
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -