码迷,mamicode.com
首页 > 编程语言 > 详细

Java Calendar and SimpleDateFormat 时间模块

时间:2019-03-16 00:24:34      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:random   void   .text   port   etl   return   led   pack   str   

package UtilTest;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import org.apache.commons.lang.RandomStringUtils;

public class TimeTest {
	static String time=null;
	public static void main(String[] args ) {
		System.out.println(getLocaltime());
		System.out.println(getfurTime(0, 0, 0, 0, 2, 0));
		System.out.println(comparetime(getLocaltime(),getfurTime(0, 0, 0, 0, 2, 0)));
		System.out.println(getrdnum());
	}
	public static String getLocaltime() {
		Calendar calendar =Calendar.getInstance();
		time=(new SimpleDateFormat(("yyyy-MM-dd  HH:mm:ss:SS"))).format(calendar.getTime());
		return time;
	}
	public static String  getfurTime(int Y,int M ,int Date,int h,int m,int s) {
		Calendar calendar =Calendar.getInstance();
		calendar.add(Calendar.YEAR,Y);
		calendar.add(Calendar.MONTH, M);
		calendar.add(Calendar.DAY_OF_MONTH, Date);
		calendar.add(Calendar.HOUR_OF_DAY, h);
		calendar.add(Calendar.MINUTE, m);
		calendar.add(Calendar.SECOND, s);
		time=(new SimpleDateFormat(("yyyy-MM-dd  HH:mm:ss:SS"))).format(calendar.getTime());
		return time;
	}
	public static boolean comparetime(String curtime,String furtime) {
		boolean bool=false;
		int res=curtime.compareTo(furtime);
		if(res<=0) {
			bool=true;
		}else if(res>0) {
			bool=false;
		}
		return  bool;
	}
	public static String getrdString() {
		String rd=RandomStringUtils.random(11, true, true);
		return rd;
	}
	public static String getrdnum() {
		String rd=RandomStringUtils.random(0, 2, 3, false, true);
		return rd;
	}
}

  

Java Calendar and SimpleDateFormat 时间模块

标签:random   void   .text   port   etl   return   led   pack   str   

原文地址:https://www.cnblogs.com/SunshineKimi/p/10540300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!