getdate.java

来自「一个用jsp技术实现的新闻发布系统」· Java 代码 · 共 92 行

JAVA
92
字号
package net.ijsp.news.util;

/**
*  Title  锋网新闻发布
*  @author: ccjsmile
*  Company: http://www.ijsp.net
*  Copyright: Copyright (c) 2003
*  @version 1.0 beta
*/

import java.util.*; 
import java.text.*; 

public class GetDate { 

	public static final long minute = 1000 * 60;

	public GetDate(){}
	
	public static Date getNowDate() { 
		Date currentTime = new Date(); 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		String dateString=formatter.format(currentTime); 
		ParsePosition pos = new ParsePosition(8); 
		Date currentTime_2 = formatter.parse(dateString, pos); 
		return currentTime_2; 
	}
	public static Date getNowDateShort() { 
		Date currentTime = new Date(); 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		String dateString=formatter.format(currentTime); 
		ParsePosition pos = new ParsePosition(8); 
		Date currentTime_2 = formatter.parse(dateString, pos); 
		return currentTime_2; 
	}
	public static String getStringDate(){
		Date currentTime = new Date(); 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String dateString = formatter.format(currentTime);
		return dateString;
	}
	public static String getStringDateShort(){
		Date currentTime = new Date(); 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(currentTime);
		return dateString;
	}
	public static Date strToDate(String strDate){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		ParsePosition pos=new ParsePosition(0); 
		Date strtodate=formatter.parse(strDate,pos);
		return strtodate;
	}
	public static String dateToStr(java.util.Date dateDate){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(dateDate);
		return dateString;	
	}
	public static Date strToBirthday(String strDate){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		ParsePosition pos=new ParsePosition(0); 
		Date strtodate=formatter.parse(strDate,pos);
		return strtodate;
	}
	public static Date getNow(){
		Date currentTime = new Date(); 
		return currentTime;
	}
	public static long getS(String strDate){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		ParsePosition pos = new ParsePosition(0); 
		Date strtodate = formatter.parse(strDate,pos);
		return strtodate.getTime();
	}
	public static long getStrToLong(String strDate){
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		ParsePosition pos = new ParsePosition(0); 
		Date strtodate = formatter.parse(strDate,pos);
		return strtodate.getTime();
	}
	public static long getLongTime() {
		return new Date().getTime();	
	}
	public static int getOffMinutes(long btime) {
        return getOffMinutes(btime, System.currentTimeMillis());
    }
	 public static int getOffMinutes(long btime, long ltime) {
        return (int) ((ltime - btime) / minute);
    }
}

⌨️ 快捷键说明

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