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. Eclipse ADT 更换主题

    如果Eclipse 版本3.6以上 在 Help→Eclipse Marketplace 搜索 Theme 之后安装即可 如果Eclipse版本3.5 一下, 通过地址安装插件: http://ecl ...

  2. Boost Thread学习笔记三

    下面先对condition_impl进行简要分析.condition_impl在其构造函数中会创建两个Semaphore(信号量):m_gate.m_queue,及一个Mutex(互斥体,跟boost ...

  3. 使用 Nginx 创建服务器的负载均衡

    译序         Nginx 的负载均衡配置看上去很简单.以下是 Nginx 官方给的一个简单的负载均衡的例子: http {   upstream myproject {     server ...

  4. java面向对象下:JavaXML解析技术

    20.JavaXML解析技术: XML概述:        XML可扩展标记性语言,用于数据表达和数据传递. XML语法规则:        合法DTDXML:1.内部DTD(和XML一起):2.外部 ...

  5. spring异常记录-----java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils

    今天在练习怎样SSH中进行单元測试的时候出现下列异常: SEVERE: Exception starting filter Struts2 java.lang.NoClassDefFoundError ...

  6. Android代码混淆和项目宣布步骤记录器

    原本放在一起Android项目与发布的文件相混淆.我突然想到,为什么不写博客,分享.有这篇文章的情况下,. Android代码混淆及项目公布步骤记录 一.清理代码中的调试信息,如Log.System. ...

  7. [C++STDlib基础]关于日期时间的操作——C++标准库头文件<ctime>

    总结 /* A.头文件<ctime> #if _GLOBAL_USING && !defined(RC_INVOKED) _STD_BEGIN 1.四个数据类型 using ...

  8. enum可以做索引

    enum可以做索引 enum可以做索引, 配上虚函数,或者函数指针,可以实现上层的统一封装和快速索引. 点击(此处)折叠或打开 MoTbl.cpp #include <stdio.h> # ...

  9. Spring配置DataSource数据源

    在Spring框架中有例如以下3种获得DataSource对象的方法: 1.从JNDI获得DataSource. 2.从第三方的连接池获得DataSource. 3.使用DriverManagerDa ...

  10. delphi中用代码实现注册Ocx和Dll(有点怪异,使用CallWindowProc来调用指定函数DllRegisterServer)

    在windows系统中,可以通过Regsvr32来实现注册ocx或者dl, 编程时,调用Regsvr32来注册,却不能正常执行.尤其是在Win7系统中,需要管理员身份才能运行. 使用下面的代码则能正常 ...