package util;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; public class TimeUtils { public static void main( String[] args ) throws ParseException{ String time = getMonth("2002-1-08 14:50:38");
System.out.println(time);
System.out.println(getDay("2002-1-08 14:50:38"));
System.out.println(TimeUtils.parseTime("2016-05-19 19:17","yyyy-MM-dd HH:mm")); }
//get current time
public static String GetNowDate(String formate){
String temp_str="";
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat(formate);
temp_str=sdf.format(dt);
return temp_str;
}
public static String getMonth( String time ){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
Date date = null;
try { date = sdf.parse(time);
Calendar cal = Calendar.getInstance();
cal.setTime(date); } catch (ParseException e) {
e.printStackTrace();
} return sdf.format(date); } public static String getDay( String time ){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try { date = sdf.parse(time);
Calendar cal = Calendar.getInstance();
cal.setTime(date); } catch (ParseException e) {
e.printStackTrace();
} return sdf.format(date); } public static Date parseTime(String inputTime) throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(inputTime); return date; }
public static String dateToString(Date date, String type) {
DateFormat df = new SimpleDateFormat(type);
return df.format(date);
}
public static Date parseTime(String inputTime, String timeFormat) throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
Date date = sdf.parse(inputTime); return date; } public static Calendar parseTimeToCal(String inputTime, String timeFormat) throws ParseException{ SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
Date date = sdf.parse(inputTime);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date); return calendar; } public static int getDaysBetweenCals(Calendar cal1, Calendar cal2) throws ParseException{ return (int) ((cal2.getTimeInMillis()-cal1.getTimeInMillis())/(1000*24*3600)); } public static Date parseTime(long inputTime){ // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date= new Date(inputTime);
return date; } public static String parseTimeString(long inputTime){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date= new Date(inputTime);
return sdf.format(date); }
public static String parseStringTime(String inputTime){ String date=null;
try {
Date date1 = new SimpleDateFormat("yyyyMMddHHmmss").parse(inputTime);
date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return date;
}
public static List<String> YearMonth(int year) {
List<String> yearmouthlist=new ArrayList<String>();
for (int i = 1; i < 13; i++) {
DecimalFormat dfInt=new DecimalFormat("00");
String sInt = dfInt.format(i);
yearmouthlist.add(year+sInt);
} return yearmouthlist;
}
public static List<String> YearMonth(int startyear,int finistyear) {
List<String> yearmouthlist=new ArrayList<String>();
for (int i = startyear; i < finistyear+1; i++) {
for (int j = 1; j < 13; j++) {
DecimalFormat dfInt=new DecimalFormat("00");
String sInt = dfInt.format(j);
yearmouthlist.add(i +"-"+sInt);
}
}
return yearmouthlist;
}
public static List<String> TOAllDay(int year){
List<String> daylist=new ArrayList<String>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
int m=1;//月份计数
while (m<13)
{
int month=m;
Calendar cal=Calendar.getInstance();//获得当前日期对象
cal.clear();//清除信息
cal.set(Calendar.YEAR,year);
cal.set(Calendar.MONTH,month-1);//1月从0开始
cal.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 System.out.println("##########___" + sdf.format(cal.getTime())); int count=cal.getActualMaximum(Calendar.DAY_OF_MONTH); System.out.println("$$$$$$$$$$________" + count); for (int j=0;j<=(count - 2);)
{
cal.add(Calendar.DAY_OF_MONTH,+1);
j++;
daylist.add(sdf.format(cal.getTime()));
}
m++;
}
return daylist;
}
//获取昨天的日期
public static String getyesterday(){
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
return yesterday;
}
}

TimeUtils(没试过)的更多相关文章

  1. meter命令行模式运行,实时获取压测结果 (没试过 说不定以后要用)

    jmeter很小,很快,使用方便,可以在界面运行,可以命令行运行.简单介绍下命令行运行的方式 上面一条命令应该可以满足大部分需求. 使用-R指定节点时,当然要首先在这些节点上启动jmeter-serv ...

  2. AppScan代理扫描app/H5安全测试(没试过,记录在此)

    标签: 1.首先设置AppScan代理,设置如下:

  3. appium--每次启动会重新安装的问题(没试过)

    有人说加这个 最后 大神说 在appium哪里就可以设置了  对,第一个不勾选就不会安装了[经理][Java]大连●Messi_Z(726862194)  15:54:10把这些东西全去掉就好了

  4. 解决jenkins拉取报告没有样式的问题(还没试过)

    来源: https://testerhome.com/topics/9476 对于测试报告来说,除了内容的简洁精炼,样式的美观也很重要.常用的做法是,采用HTML格式的文档,并搭配CSS和JS,实现自 ...

  5. QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAllocEx failed.(遇到还没试过)

    今天在使用Redis的时候出现以下错误: QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAll ...

  6. Mybatis中的@Param注解(自己没试过)

    @Param是MyBatis所提供的(org.apache.ibatis.annotations.Param),作为Dao层的注解,作用是用于传递参数,从而可以与SQL中的的字段名相对应//https ...

  7. python 调用java脚本的加密(没试过,先记录在此)

    http://lemfix.com/topics/344 前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公 ...

  8. 在Mac 搭建robotframework 环境 遇到ride.py 打不开的方法(没试过,先记录在此)

    折腾来一下午,遇到了好多坑 坑 1.不要用pip 下载wxpython 2.不要用mac自带的python 3.不要自己下载wxpython 步骤: 1. 安装homebrew, /usr/bin/r ...

  9. springboot 使用consul 读取配置文件(遇到的坑太多,没记录)

    最终成功版. pom引入mavn依赖: <!--consul--> <dependency> <groupId>org.springframework.cloud& ...

随机推荐

  1. jvm基础(2)

    7.类装载器 (1)class装载验证流程: A加载.这是装载类的第一个阶段,执行的动作包括:取得类的二进制流,转为方法区数据结构,在java堆中生成对应的java.lang.Class对象. B链接 ...

  2. 【Web探索之旅】第三部分第一课:server

    wx_fmt=jpeg" alt="0? wx_fmt=jpeg" style="height:auto"> 内容简单介绍 .第三部分第一课:s ...

  3. javascript 获取当前日期 月份 时间

    <script type="text/javascript"> function getDate() { var date = new Date(); //得到当前日期 ...

  4. c#4.5新语法--自动属性和隐式类型

    1.自动属性    自动属性是c#中属性定义的两种形式的一种:传统属性定义.自动属性.    1.1 传统属性定义        private int _age;        public int ...

  5. java之异常的捕获及处理

    在java中程序的错误主要是语法错误和语义错误(也就是逻辑错误). java中异常处理语句的格式: try{ //有可能出现异常的语句 }catch(异常类 异常对象){ //编写异常的处理语句 }c ...

  6. ubuntu12.04离线安装libjpeg62-dev

    0:如果的电脑能连接上网络,用apt-get install安装最爽,我的情况是:公司电脑用的内网,访问不了外网,而且不让访问外网,安装软件只能用u盘拷进去再安装,所以我用如下方法 1:下载安装包,地 ...

  7. delphi如何让程序最小化到任务栏(使用Shell_NotifyIcon API函数)

    现在很多的应用程序都有这样一种功能,当用户选择最小化窗口时,窗口不是象平常那样最小化到任务栏上,而是“最小化”成一个任务栏图标.象FoxMail 3.0 NetVampire 3.0等都提供了这样的功 ...

  8. [haoi2014]贴海报

    Bytetown城市要进行市长竞选,所有的选民可以畅所欲言地对竞选市长的候选人发表言论.为了统一管理,城市委员会为选民准备了一个张贴海报的electoral墙.张贴规则如下:1.electoral墙是 ...

  9. HDU2512 一卡通大冒险 —— 第二类斯特林数

    题目链接:https://vjudge.net/problem/HDU-2512 一卡通大冒险 Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  10. Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分

    题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...