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 处理时间的各种方式——获取时间——时间格式化的更多相关文章

  1. Java非递归的方式获取目录中所有文件(包括目录)

    零.思路解析 对于给出的文件查看其下面的所有目录,将这个目录下的所有目录放入待遍历的目录集合中,每次取出该集合中的目录遍历,如果是目录再次放入该目录中进行遍历. 一.代码 /** * 非递归的方式获取 ...

  2. java 编程基础 反射方式获取泛型的类型Fileld.getGenericType() 或Method.getGenericParameterTypes(); (ParameterizedType) ;getActualTypeArguments()

    引言 自从JDK5以后,Java Class类增加了泛型功能,从而允许使用泛型来限制Class类,例如,String.class的类型实际上是 Class 如果 Class 对应的类暂时未知,则使 C ...

  3. java获取当前日期时间代码总结

    1.获取当前时间,和某个时间进行比较.此时主要拿long型的时间值.  方法如下: 要使用 java.util.Date .获取当前时间的代码如下  代码如下 复制代码 Date date = new ...

  4. 使用Calender类获取系统时间和时间和运算

    使用Calender类获取系统时间和时间和运算: @Test public void testCal(){ //使用Calender对象获取时间,并对时间进行计算: Calendar instance ...

  5. Java基础进阶:时间类要点摘要,时间Date类实现格式化与解析源码实现详解,LocalDateTime时间类格式化与解析源码实现详解,Period,Duration获取时间间隔与源码实现,程序异常解析与处理方式

    要点摘要 课堂笔记 日期相关 JDK7 日期类-Date 概述 表示一个时间点对象,这个时间点是以1970年1月1日为参考点; 作用 可以通过该类的对象,表示一个时间,并面向对象操作时间; 构造方法 ...

  6. Java中获取系统时间的四种方式

    第一种: Date day=new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...

  7. java 获取系统当前时间并格式化

      java 获取系统当前时间并格式化 CreateTime--2018年5月9日11:41:00 Author:Marydon 实现方式有三种 updateTime--2018年7月23日09点32 ...

  8. Java获取系统时间少了八个小时

    Java获取系统时间少了八个小时 今天忽然遇到需要获取当前时间的问题,我向来谨慎,先测试获取到的系统时间是否正确,结果竟然发现少了八个小时,晕死了,记得之前在页面用javascript获取过当前时间, ...

  9. java学习第13天( java获取当前时间,有关大数据的运算及精确数字运算,Date类)

    一 java获取当前时间 学习一个函数,得到当前时间的准确值 System.currectTimeMillis(). 可以得到以毫秒为单位的当前时间.它主要用于计算程序运行时间,long start= ...

随机推荐

  1. Swift - 使用ALAssetsLibrary获取相簿里所有图片,视频(附样例)

    1,ALAssetsLibrary介绍 (1)通过创建ALAssetsLibrary的实例可以访问系统Photos里的图片与视频.这里图片不仅包括相机拍摄的照片,还包括从iTunes导入的和从其他设备 ...

  2. MapReduce整体架构分析

    继前段时间分析Redis源代码一段时间之后.我即将開始接下来的一段技术学习的征程.研究的技术就是当前很火热的Hadoop,可是一个Hadoop生态圈是很庞大的.所以首先我的打算是挑选当中的一部分模块, ...

  3. [置顶] ARM-Linux下WEB服务器Boa的移植、配置和运行测试

    Linux下使用的轻量级WEB服务器主要有:lighttpd.thttpd.shttpd和boa等等,而Boa是使用最为广泛的轻量级WEB服务器之一(当然,阿帕奇是世界使用排名第一的Web服务器软件) ...

  4. Appium Server 传递iOS参数

    Appium  server  iOS Capabilities 参数 iOS Only Capability Description Values calendarFormat (Sim-only) ...

  5. 网页插入QQ 无需加好友

    <p>联系方式:1073351325<a href="tencent://message/?Menu=yes&uin=1073351325&Site=dsf ...

  6. hdu 4704 同余定理+普通快速幂

    此题往后推几步就可找到规律,从1开始,答案分别是1,2,4,8,16.... 这样就可以知道,题目的目的是求2^n%Mod的结果.....此时想,应该会想到快速幂...然后接着会发现,由于n的值过大, ...

  7. Nginx和Tomcat负载均衡实现session共享(转)

    以前的项目使用Nginx作为反向代理实现了多个Tomcat的负载均衡,为了实现多个Tomcat之间的session共享,使用了开源的Memcached-Session-Manager框架. 此框架的优 ...

  8. CSS 控制应为Html页面高度导致抖动的问题

    在CSS中添加如下代码: html,body{ overflow-y:scroll;} html,body{ overflow:scroll; min-height:101%;} html{ over ...

  9. Git权威指南学习笔记(二)Git暂存区

    例如以下图所看到的: 左側为工作区,是我们的工作文件夹. 右側为版本号库,当中: index标记的是暂存区(stage),所处文件夹为.git/index,记录了文件的状态和变更信息. master标 ...

  10. Swift - 复杂数据类型说明(数组,字典,结构体,枚举)

    1,数组 - Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 var types ...