java日期工具类

 //取一天中的hour值
	public static int calendarForHour() {
		Calendar calendar = Calendar.getInstance();
		int hour = calendar.get(Calendar.HOUR_OF_DAY);
		return hour;
	}
	//生成完整的日期格式
	public static String getDateFormat() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Date date = new Date();
		String time = simpleDateFormat.format(date);
		return time;
	}
	//得到当前系统日期 例:2008-07-25
	public synchronized static String getSysDate() {
	      java.sql.Timestamp timeStamp = new java.sql.Timestamp(System.currentTimeMillis());
	       return timeStamp.toString().substring(0,10);
	    } 
	//得到当前系统的日期和时间,精确到秒,例:2008-07-25 14:17:34
    public static String getSysTimeStamp() {
    	java.sql.Timestamp timeStamp = new java.sql.Timestamp(System.currentTimeMillis());
        return timeStamp.toString().substring(0,19);
    }

你可能感兴趣的:(java,sql)