首页>代码>HTML5 录制视频 + 上传>/HTML5Video/src/main/java/com/demo/util/DateUtil.java
package com.demo.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * 
 * 时间工具
 * 
 * @author lee
 * @since 2017/2/17 10:50:00
 * 
 */
public class DateUtil {
	
	
	
	public static void main(String[] args) {
		isinvalidate2();
	}
	// private static SimpleDateFormat simpleDateFormat = new
	// SimpleDateFormat();

	private static ThreadLocal<SimpleDateFormat> local = new ThreadLocal<SimpleDateFormat>();

	/**
	 * 获取当前时间
	 * 
	 * @return 当前时间格式化后的字符串 示例: "2000-10-0 18:00:00"
	 */
	public static String getCurrentTime() {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
	}

	/**
	 * 获取当前格式化时间
	 * 
	 * @param pattern
	 *            - 时间格式 示例: "yyyy-MM-dd HH:mm:ss"
	 * @return 当前时间格式化后的字符串 示例: "2000-10-0 18:00:00"
	 * 
	 *         解决方案1
	 * 
	 */
	public static String getCurrentTime(String pattern) {
		return new SimpleDateFormat(pattern).format(new Date());
	}

	public static String simpleDateformatDate(String pattern, Date date) {

		return new SimpleDateFormat(pattern).format(date);
	}

	/**
	 * 
	 * 
	 * 
	 * 解决方案2
	 * 
	 */
	public static Date simpleDateparseDate(String pattern, String dateStr) throws ParseException {
		return new SimpleDateFormat(pattern).parse(dateStr);
	}

	public static Date parseDate(String pattern, String str) throws ParseException {
		SimpleDateFormat sdf = local.get();
		if (sdf == null) {
			sdf = new SimpleDateFormat(pattern, Locale.US);
			local.set(sdf);
		}
		try {
			return sdf.parse(str);
		} catch (ParseException e) {

			e.printStackTrace();
		}
		return new SimpleDateFormat(pattern).parse(str);
	}

	public static String formatDate(String pattern, Date date) {
		SimpleDateFormat sdf = local.get();
		if (sdf == null) {
			sdf = new SimpleDateFormat(pattern, Locale.US);
			local.set(sdf);
		}
		return sdf.format(date);
	}
	
	public static boolean isinvalidate(Date date){
		  if (new Date().getTime()<date.getTime()){ 
			  return false;
		  }else{ 
			  return true;
		  } 
	}
	/*
	 * date1 <当前时间 <date2 返回true 
	 * 
	 * 
	 */
	public static boolean isinvalidate2(){
		 SimpleDateFormat ft = new SimpleDateFormat("HH:mm:ss");  
		  Calendar calender = Calendar.getInstance();
		  int hour = calender.get(Calendar.HOUR_OF_DAY);
		  int minute = calender.get(Calendar.MINUTE);
		  int second = calender.get(Calendar.SECOND);
		if (hour>5&&minute>30&&hour<8&&minute<30){ 
			return true;
		}else{ 
			return false;
		} 
	}
	public static String getLast2Day() {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DAY_OF_YEAR, -2);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		return DateUtil.formatDate("yyyy-MM-dd HH:mm:ss", c.getTime());
	}
}
最近下载更多
sjc199  LV2 2022年6月13日
13613768985  LV1 2022年5月13日
han329574  LV8 2021年12月5日
空空空  LV1 2021年7月20日
871505903  LV4 2021年4月26日
lktkitty  LV1 2020年12月7日
a770919458  LV1 2020年10月29日
无聊de人  LV1 2020年7月27日
yantingbin2012  LV1 2020年7月13日
liumingliang  LV1 2020年7月11日
最近浏览更多
hmf1989 昨天
暂无贡献等级
15103432984  LV2 3月16日
3334004690  LV3 3月6日
pangzhihui  LV12 2023年12月15日
uni-code_0123  LV1 2023年11月29日
微信网友_6696101153525760 2023年10月17日
暂无贡献等级
fesfefe  LV13 2023年9月21日
yangxb2  LV10 2023年9月12日
微信网友_6600229376544768  LV1 2023年8月10日
dongzhan  LV12 2023年6月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友