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. EL表达式(2)

    本篇介绍EL表达式的隐式对象,如同JSP一样,EL也封装了11个隐式对象,通过这些隐式对象可以在EL表达式中直接使用. 在使用EL时,其实EL是先看标识符是否是其隐式对象之一,如果不是,才从四个域(p ...

  2. LaTeX新人教程,30分钟从全然陌生到基本入门

    1.LaTeX软件的安装和使用  方法A(自助):在MikTeX的官网下载免费的MikTeX编译包并安装.下载WinEdt(收费)或TexMaker(免费)等编辑界面软件并安装.  方法B(打包):在 ...

  3. 百度贴吧客户端(Android)网络通信行为分析

    百度贴吧安卓客户端网络通信行为分析 本文由CSDN-蚍蜉撼青松[主页:http://blog.csdn.net/howeverpf]原创,转载请注明出处! 一.实验环境与结果概述 1.1 实验环境   ...

  4. C2B未来:大数据定制

    昨天看到微信SuperSofter写了一篇文章,有感而发.以便备记. 这是一种典型的C2B模式.阿里不仅仅是在与腾讯拼移动.它的电商本土业务也在稳步推进.近期一个里程碑事件是.阿里包下了美的.九阳.苏 ...

  5. 纯后端尝试写一个前端slide插件

    概述 由于项目组前端人员缺失,又赶上需要在手机端做一个slide效果的页面,所以只能自己硬着头皮上了,写的很简单,请大家不要笑话,只是拿出来分享下,大家先看下完成后的效果,如下: 过程 看了效果图是不 ...

  6. 与众不同 windows phone (12) - Background Task(后台任务)之 PeriodicTask(周期任务)和 ResourceIntensiveTask(资源密集型任务)

    原文:与众不同 windows phone (12) - Background Task(后台任务)之 PeriodicTask(周期任务)和 ResourceIntensiveTask(资源密集型任 ...

  7. cocos2dX 事件之触摸事件和触摸事件集合

    今天, 我们来学习cocos2dX里面的触摸事件与触摸事件合集, 如今的手机游戏交互基本上都是通过触摸交互的, 所以大家明确这节的重要性了吧, 本节篇幅比較大, 所以我就不扯闲话了 先来看看经常使用函 ...

  8. JXL 读取 Excel java中jxl导出数据到excel的例子 上传文件

    2010-10-14 19:17:06 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info 信息: Entferne Dat ...

  9. svn自动备份

    #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH DATE=` ...

  10. hdu2647 逆拓扑,链式前向星。

    pid=2647">原文地址 题目分析 题意 老板发工资,可是要保证发的工资数满足每一个人的期望,比方A期望工资大于B,仅仅需比B多1元钱就可以.老板发的最低工资为888元.输出老板最 ...