TimeUtils(没试过)
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(没试过)的更多相关文章
- meter命令行模式运行,实时获取压测结果 (没试过 说不定以后要用)
jmeter很小,很快,使用方便,可以在界面运行,可以命令行运行.简单介绍下命令行运行的方式 上面一条命令应该可以满足大部分需求. 使用-R指定节点时,当然要首先在这些节点上启动jmeter-serv ...
- AppScan代理扫描app/H5安全测试(没试过,记录在此)
标签: 1.首先设置AppScan代理,设置如下:
- appium--每次启动会重新安装的问题(没试过)
有人说加这个 最后 大神说 在appium哪里就可以设置了 对,第一个不勾选就不会安装了[经理][Java]大连●Messi_Z(726862194) 15:54:10把这些东西全去掉就好了
- 解决jenkins拉取报告没有样式的问题(还没试过)
来源: https://testerhome.com/topics/9476 对于测试报告来说,除了内容的简洁精炼,样式的美观也很重要.常用的做法是,采用HTML格式的文档,并搭配CSS和JS,实现自 ...
- QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAllocEx failed.(遇到还没试过)
今天在使用Redis的时候出现以下错误: QForkMasterInit: system error caught. error code=0x000005af, message=VirtualAll ...
- Mybatis中的@Param注解(自己没试过)
@Param是MyBatis所提供的(org.apache.ibatis.annotations.Param),作为Dao层的注解,作用是用于传递参数,从而可以与SQL中的的字段名相对应//https ...
- python 调用java脚本的加密(没试过,先记录在此)
http://lemfix.com/topics/344 前言 自动化测试应用越来越多了,尤其是接口自动化测试. 在接口测试数据传递方面,很多公司都会选择对请求数据进行加密处理. 而目前为主,大部分公 ...
- 在Mac 搭建robotframework 环境 遇到ride.py 打不开的方法(没试过,先记录在此)
折腾来一下午,遇到了好多坑 坑 1.不要用pip 下载wxpython 2.不要用mac自带的python 3.不要自己下载wxpython 步骤: 1. 安装homebrew, /usr/bin/r ...
- springboot 使用consul 读取配置文件(遇到的坑太多,没记录)
最终成功版. pom引入mavn依赖: <!--consul--> <dependency> <groupId>org.springframework.cloud& ...
随机推荐
- vim 自动补全
1. vim编辑器自带关键字补全 触发: ctrl + n or ctrl + p 补全命令: <C-n> 普通关键字 [能够根据buffer以及标签文件列表等 ...
- Spring Cloud(十二):Spring Cloud Zuul 限流详解(附源码)(转)
前面已经介绍了很多zuul的功能,本篇继续介绍它的另一大功能.在高并发的应用中,限流往往是一个绕不开的话题.本文详细探讨在Spring Cloud中如何实现限流. 在 Zuul 上实现限流是个不错的选 ...
- gulp css html image js 合并压缩
安装node.js npm 以及安装gulp等方法我就不在这里赘述了. 接下里我主要介绍的是Gulpfile文件里面的配置该如何书写. var gulp = require('gulp');//引 ...
- iOS 浅赋值、深复制、全然复制的知识点梳理验证(附加归档解档)
写于前: 在之前转载的一片文章中.文中对浅复制和深复制进行了具体的解读,同一时候还提到了深复制(one-level-deep copy).全然复制(true copy)的概念,并指出iOS开发中的深复 ...
- 如何清除本地DNS缓存 windows
在您的网站迁移服务器时需要对域名所指向的IP进行更改,这时候在本机访问网站时就需要清除本地的DNS缓存信息,那么怎样清除呢? 首先我们应该明白清除DNS缓存信息的原理:当计算机对域名访问时并不是每次访 ...
- iphone开发的技巧
一,改动状态栏: 1.增加[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];但此方法仅仅是不显示状态条,状态 ...
- EasyDarwin开源流媒体服务器实现RTSP直播同步输出MP4、RTMP、HLS的方案思路
背景 近期跟开源团队商量,想在EasyDarwin上继续做一些功能扩展,目前EasyDarwin开源流媒体服务器只能够实现高效的RTSP推流直播转发/分发功能,输入与输出都是RTSP/RTP流,不能够 ...
- from memory cache
from memory cache
- three supported reliability levels: * End-to-end * Store on failure * Best effort
https://github.com/cloudera/flume/blob/master/flume-docs/src/docs/UserGuide/Introduction === Reliabi ...
- 推荐一个非常好的 IntelliJ IDEA 教程
教程地址:https://github.com/judasn/IntelliJ-IDEA-Tutorial 作者博客:http://www.youmeek.com/category/software- ...