java 处理时间的各种方式——获取时间——时间格式化
TimeUtil.java
package com.snow; import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date; public class TimeUtil { /**
* 获取当前时间 格式为 2016-06-16 10:32:53
*
* @return String
* @author jingxue.chen
* @date 2016-6-16 上午10:33:27
*/
public static String getCurrentTimeSceond() { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=format.format(new Date());
return time;
} /**
* 获取当前时间 加10分钟 格式为 2016-06-16 10:42:53
*
* @return String
* @author jingxue.chen
* @date 2016-6-16 上午10:33:32
*/
public static String getAfterTenTimeSceond() { long currentTime = System.currentTimeMillis() + 10 * 60 * 1000;
Date date = new Date(currentTime);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowTime=df.format(date);
return nowTime;
} /**
* 获取当前时间的 时分 格式为 2016-06-16 10:32
*
* @return String
* @author jingxue.chen
* @date 2016-6-16 上午10:33:39
*/
public static String getCurrentTimeMinute() { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String time=format.format(new Date());
return time;
}
/**
* 获取当前时间 年月 格式为 2016-06-16
*
* @return String
* @author jingxue.chen
* @date 2016-6-16 上午10:33:47
*/
public static String getCurrentTimeDay() { DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String time=format.format(new Date());
return time;
} /**
* 获取时间,格式为 201606161032053
*
* @return String
* @author jingxue.chen
* @date 2016-6-16 上午10:34:09
*/
public static String getuniqukey() { DateFormat format = new SimpleDateFormat("yyyyMMddHHmmsss");
String time=format.format(new Date());
return time;
} /**
* 将 Date 转换为 时间格式 格式为 yyyy-MM-dd HH:mm:ss
*
* @param date
* @return String
* @author jingxue.chen
* @date 2016-6-16 上午10:33:50
*/
public static String convertTimeSceond(Date date) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=format.format(date);
return time;
} /**
* 将 Date 转换为 时间格式 格式为 yyyy-MM-dd
*
* @param date
* @return String
* @author jingxue.chen
* @date 2016-6-16 上午10:33:54
*/
public static String convertTimeDay(Date date) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String time=format.format(date);
return time;
} /**
* 将 String格式的时间 转换为 时间格式 格式为 Thu Jun 16 10:52:53 CST 2016
*
* @param time
* @return Date
* @author jingxue.chen
* @date 2016-6-16 上午10:33:57
*/
public static Date convertDateSceond(String time) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=null;
try {
date = format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
} /**
* 将 String格式的时间 转换为 时间格式 格式为 Thu Jun 16 00:00:00 CST 2016
*
* @param time
* @return Date
* @author jingxue.chen
* @date 2016-6-16 上午10:34:01
*/
public static Date convertDateDay(String time) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date=null;
try {
date = format.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
} /**
* 判断 第一个时间是否大于第二个时间 false
*
* @param date1
* @param date2
* @return boolean
* @author jingxue.chen
* @date 2016-6-16 上午10:34:05
*/
public static boolean compDate(String date1,String date2) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
boolean time=false;
try {
Date dates1 = format.parse(date1);
Date dates2 = format.parse(date2);
if(dates1.getTime()>dates2.getTime()){
time=true;
}
} catch (ParseException e) {
e.printStackTrace();
}
return time;
} }
java 处理时间的各种方式——获取时间——时间格式化的更多相关文章
- Java非递归的方式获取目录中所有文件(包括目录)
零.思路解析 对于给出的文件查看其下面的所有目录,将这个目录下的所有目录放入待遍历的目录集合中,每次取出该集合中的目录遍历,如果是目录再次放入该目录中进行遍历. 一.代码 /** * 非递归的方式获取 ...
- java 编程基础 反射方式获取泛型的类型Fileld.getGenericType() 或Method.getGenericParameterTypes(); (ParameterizedType) ;getActualTypeArguments()
引言 自从JDK5以后,Java Class类增加了泛型功能,从而允许使用泛型来限制Class类,例如,String.class的类型实际上是 Class 如果 Class 对应的类暂时未知,则使 C ...
- java获取当前日期时间代码总结
1.获取当前时间,和某个时间进行比较.此时主要拿long型的时间值. 方法如下: 要使用 java.util.Date .获取当前时间的代码如下 代码如下 复制代码 Date date = new ...
- 使用Calender类获取系统时间和时间和运算
使用Calender类获取系统时间和时间和运算: @Test public void testCal(){ //使用Calender对象获取时间,并对时间进行计算: Calendar instance ...
- Java基础进阶:时间类要点摘要,时间Date类实现格式化与解析源码实现详解,LocalDateTime时间类格式化与解析源码实现详解,Period,Duration获取时间间隔与源码实现,程序异常解析与处理方式
要点摘要 课堂笔记 日期相关 JDK7 日期类-Date 概述 表示一个时间点对象,这个时间点是以1970年1月1日为参考点; 作用 可以通过该类的对象,表示一个时间,并面向对象操作时间; 构造方法 ...
- Java中获取系统时间的四种方式
第一种: Date day=new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...
- java 获取系统当前时间并格式化
java 获取系统当前时间并格式化 CreateTime--2018年5月9日11:41:00 Author:Marydon 实现方式有三种 updateTime--2018年7月23日09点32 ...
- Java获取系统时间少了八个小时
Java获取系统时间少了八个小时 今天忽然遇到需要获取当前时间的问题,我向来谨慎,先测试获取到的系统时间是否正确,结果竟然发现少了八个小时,晕死了,记得之前在页面用javascript获取过当前时间, ...
- java学习第13天( java获取当前时间,有关大数据的运算及精确数字运算,Date类)
一 java获取当前时间 学习一个函数,得到当前时间的准确值 System.currectTimeMillis(). 可以得到以毫秒为单位的当前时间.它主要用于计算程序运行时间,long start= ...
随机推荐
- cocos2dx3.2 异步载入和动态载入
半个月没有更新博客,从这个项目開始学习了非常多细节的东西,都不太成系统.可是却是开发上线中必须经历的东西.比方超级玛丽系列(一)中的正确的异步载入,正确的分层.正确的合成和载入plist.及时的移除未 ...
- C++学习之路—继承与派生(二):派生类的构造函数与析构函数
(根据<C++程序设计>(谭浩强)整理,整理者:华科小涛,@http://www.cnblogs.com/hust-ghtao转载请注明) 由于基类的构造函数和析构函数是不能被继承的,所以 ...
- DWZ (JUI) 教程(二):处理信息回馈的通用规范
在开发过程中,抽象成模型,定义规范是非常有必要的,不仅可以简化代码,提高开发效率,也为自己减少了不少麻烦. 在开发中,因为DWZ这块是我负责,由于代码琐碎,重复度高,没有抽象封装,没有定义规范,别人不 ...
- 7个基于Linux命令行的文件下载和网站浏览工具
7个基于Linux命令行的文件下载和网站浏览工具 时间:2015-06-01 09:36来源:linux.cn 编辑:linux.cn 点击: 2282 次 Linux命令行是GNU/Linux中最神 ...
- awk 正则表达式
awk 正则表达式.正则运算符详细介绍 前言:使用awk作为文本处理工具,正则表达式是少不了的. 要掌握这个工具的正则表达式使用.其实,我们不必单独去学习它的正则表达式.正则表达式就像一门程序语言,有 ...
- 利用Xtrabackup备份集合恢复一台从库的过程
1 time tar -xvf Open..tarx.gz real 35m22.502s user 10m16.499s sys 1m28.578s You have new m ...
- 手动配置S2SH三大框架报错(一)
十二月 08, 2013 9:24:51 下午 org.apache.catalina.core.AprLifecycleListener init 严重: An incompatible versi ...
- ZeroMQ:云计算时代最好的通讯库
还在学socket编程吗?还在研究为什么epoll比select更好吗? 噢,不必了! 在复杂的云计算环境中,我们面临的难题远比这个复杂得多. 庞大的服务器集群作为计算云,对来来看或许只是一个简单的搜 ...
- A Very Easy Triangle Counting Game
题意:在圆上取n个点,相邻两个点之间连线,(注意,n和1相邻),然后所有点对(i ,i+2)相连,问能形成的不同的三角形有多少个? 思路:找规律 n=3,cnt=1; n=4,cnt=8; n=5 c ...
- Swift - 滑块(UISlider)的用法
1,滑块的创建 1 2 3 4 5 6 var slider=UISlider(frame:CGRectMake(0,0,300,50)) slider.center=self.view.center ...