Java中日期操作
编程技术  /  houtizong 发布于 3年前   71
package com.zx.common.util;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class DateUtil { private static final String FORMAT="yyyy-MM-dd HH:mm:ss"; public static Date getTime(){Calendar now=Calendar.getInstance();return now.getTime();}public static String formatTime(Date time){SimpleDateFormat sdf=new SimpleDateFormat(FORMAT);return sdf.format(time);}public static String getCurrentTime(){Calendar now=Calendar.getInstance();StringBuffer time=new StringBuffer();time.append(now.get(now.YEAR));time.append(now.get(now.MONTH)+1);time.append(now.get(now.DAY_OF_MONTH));time.append(now.get(now.HOUR));time.append(now.get(now.MINUTE));time.append(now.get(now.SECOND));return time.toString();}/** * 判断是否在发短信的时间范围内(8:00-23:00) (penghuaiyi 2008-12-22) * @return */public static boolean isSendTime(){boolean flag=false;Calendar current=Calendar.getInstance();int year=current.get(Calendar.YEAR);int month=current.get(Calendar.MONTH);int date=current.get(Calendar.DAY_OF_MONTH); //设置短信发送开始时间:8:00current.set(year, month, date, BEGIN_TIME,0,0);Date beginTime=current.getTime();//设置短信发送截止时间:23:00current.set(year, month, date, END_TIME,0,0);Date endTime=current.getTime();Date now=new Date(); //当前时间if(now.after(beginTime) && now.before(endTime)){flag=true;}return flag;}public static void main(String args[]){ Date date=DateUtil.getTime(); String time=DateUtil.formatTime(date); System.out.println(time); String str=DateUtil.getCurrentTime(); System.out.println(str);}}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接