首页 > 编程语言 > 详细

Java Calendar and SimpleDateFormat 时间模块

时间:2019-03-16 00:48:51      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:minute   compare   div   ack   orm   ava   lse   .get   end   

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 时间模块

标签:minute   compare   div   ack   orm   ava   lse   .get   end   

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

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号