dateutil.java

来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 71 行

JAVA
71
字号
/**  * File and FTP Explorer  * Copyright 2003  * BOESCH Vincent  *  * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  */package javaexplorer.util;import java.util.Calendar;import java.util.Date;/** * Utilitaires sur les dates * <p>Title: JExp</p> * <p>Description: File, FTP Explorer</p> * <p>Copyright: 2003</p> * <p>Company: N/A</p> * @author BOESCH Vincent * @version 4.4 */public class DateUtil {    /**     *  Renvoie la date     *     *@param  lngDate    Description of the Parameter     *@param  intFormat  Description of the Parameter     *@return            Description of the Return Value     */    public static String formatDate(long lngDate) {        if (lngDate <= 0) {            return "N/A";        }        Calendar cal = Calendar.getInstance();        cal.setTime(new Date(lngDate));        int day = cal.get(Calendar.DAY_OF_MONTH);        int month = cal.get(Calendar.MONTH) + 1;        int year = cal.get(Calendar.YEAR);        int hour = cal.get(Calendar.HOUR_OF_DAY);        int min = cal.get(Calendar.MINUTE);        int sec = cal.get(Calendar.SECOND);        StringBuffer sbDate = new StringBuffer();        sbDate.append(year).append("/");        sbDate.append(((month < 10) ? "0" : "") + month).append("/");        sbDate.append(((day < 10) ? "0" : "") + day).append(" ");        sbDate.append(((hour < 10) ? "0" : "") + hour).append(":");        sbDate.append(((min < 10) ? "0" : "") + min).append(":");        sbDate.append(((sec < 10) ? "0" : "") + sec);        return sbDate.toString();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?