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. 怎样将Emoj表情插入mysql5.6数据库__python+mysqldb

    废话不多说,相信看到这里的看客已经看过非常多配置文件的设置方法.可是问题还是没有解决.本文就具体记录一下我的解决方法吧. 我的环境:mysql5.6+python2.7.3+MySQLdb1.2.4 ...

  2. VC实现文件拖拽OnDropFiles

    文章转自http://blog.csdn.net/zamaolangzi/article/details/5645284 使用过QQ的人都知道,只要把文件拖拽到消息框中就可以传送文件了.那么这种功能是 ...

  3. 14.6.3 Grouping DML Operations with Transactions 组DML操作

    14.6.3 Grouping DML Operations with Transactions 组DML操作 默认情况下,连接到MySQL server 开始是以启动自动提交模式, 会自动提交每条S ...

  4. 几款屏幕录制软件 ActivePresente

    几款屏幕录制软件,最强大是  ActivePresenter ,免费版, 足以应对我们日常需求.列表如下 支持系统:W-Windows,L-Linux,M-Mac 软件 格式 W L M 免费 说明 ...

  5. fake it till you become it

    fake it till you become it_你泛起山川烟波里的不是我._百度空间 fake it till you become it

  6. (step6.3.2)hdu 1068(Girls and Boys——二分图的最大独立集)

    题目大意:第一行输入一个整数n,表示有n个节点.在接下来的n行中,每行的输入数据的格式是: 1: (2) 4 6 :表示编号为1的人认识2个人,他们分别是4.6: 求,最多能找到多少个人,他们互不认识 ...

  7. fastjson 之常见的数据类型与json的相互转换

    public class FastJsonTest1 { /** * 数组转json格式字符串 */ public void array2Json(){ String[] arr = {"b ...

  8. js弹出对话框,遮罩效果,

    刚刚来到实习单位,我跟着廖哥做项目.然后他分配给我一个小小的任务,实现起来总的效果如下: 然后,但我们单击显示数目这个链接的时候,就会弹出一个又遮罩效果的对话框,如下图: 当我们在对话框中再点击里面的 ...

  9. SVN的项目管理

    基于SVN的项目管理——集中与分散   我们在此处不讨论 GIT 比 SVN 好多少,也不讨论 Maven 和 Gradle 哪个好用,基于现有的开发环境,大多数公司还是采用 SVN + Maven ...

  10. Delphi读写UTF-8、Unicode格式文本文件

    // UTF-8文件写入函数procedure SaveUTFFile(const FileName: string; S: string; WriteHeader: Boolean = True); ...