java的时间
先看例子:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar; public class DateTest
{
public static void main(String[] args)
{
Date date = new Date();
System.out.println("Today**********");
printDate(date); GregorianCalendar d = new GregorianCalendar();
d.add(Calendar.DAY_OF_MONTH, -1);
Date yesterDate = d.getTime();
System.out.println("Yesterday**********");
printDate(yesterDate);
} private static void printDate(Date date)
{
System.out.printf("epoch毫秒数: %s%n", date.getTime());
System.out.printf("LONG Date: %s%n", DateFormat.getDateInstance(DateFormat.LONG));
System.out.printf("SHORT Date: %s%n", DateFormat.getDateInstance(DateFormat.SHORT)); System.out.printf("LONG Time: %s%n", DateFormat.getTimeInstance(DateFormat.LONG));
System.out.printf("SHORT Time: %s%n", DateFormat.getTimeInstance(DateFormat.SHORT)); System.out.printf("LONG DateTime: %s%n", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG));
System.out.printf("SHORT DateTime: %s%n", DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.printf("指定格式: %s%n", df.format(date));
}
}
输出:
Today**********
epoch毫秒数: 1534952854644
LONG Date: java.text.SimpleDateFormat@a87fc158
SHORT Date: java.text.SimpleDateFormat@d5391ab7
LONG Time: java.text.SimpleDateFormat@787e63cb
SHORT Time: java.text.SimpleDateFormat@58715d3
LONG DateTime: java.text.SimpleDateFormat@a0ba3d93
SHORT DateTime: java.text.SimpleDateFormat@b5341f2a
指定格式: 2018-08-22 23:47:34
Yesterday**********
epoch毫秒数: 1534866454874
LONG Date: java.text.SimpleDateFormat@a87fc158
SHORT Date: java.text.SimpleDateFormat@d5391ab7
LONG Time: java.text.SimpleDateFormat@787e63cb
SHORT Time: java.text.SimpleDateFormat@58715d3
LONG DateTime: java.text.SimpleDateFormat@a0ba3d93
SHORT DateTime: java.text.SimpleDateFormat@b5341f2a
指定格式: 2018-08-21 23:47:34
java的时间的更多相关文章
- Java实现时间动态显示方法汇总
这篇文章主要介绍了Java实现时间动态显示方法汇总,很实用的功能,需要的朋友可以参考下 本文所述实例可以实现Java在界面上动态的显示时间.具体实现方法汇总如下: 1.方法一 用TimerTask: ...
- Java 对时间和日期的相关处理
1. 获取当前系统时间和日期并格式化输出 import java.util.Date; import java.text.SimpleDateFormat; public class NowStrin ...
- java中时间的获取(二)
java中时间的获取2 /** * 获取数据库操作记录时间 */ public static String getOpreateDbTime() { Calendar c = Calendar.get ...
- Java 日期时间
Java 日期时间 标签 : Java基础 Date java.util.Date对象表示一个精确到毫秒的瞬间; 但由于Date从JDK1.0起就开始存在了,历史悠久,而且功能强大(既包含日期,也包含 ...
- JAVA格式化时间日期
JAVA格式化时间日期 import java.util.Date; import java.text.DateFormat; /** * 格式化时间类 * DateFormat.FULL = 0 * ...
- Java日期时间使用(转)
Java日期时间使用总结 转自:http://lavasoft.blog.51cto.com/62575/52975/ 一.Java中的日期概述 日期在Java中是一块非常复杂的内容,对于一个 ...
- Java格式化时间
Java格式化时间 将秒或者毫秒值格式化成指定格式的时间 效果图 工具类 工具类里我只列出了一种格式的格式化方式,可以根据自己的需求,修改"yyyy-MM-dd hh:mm:ss" ...
- java Date时间的各种转换方式和Mysql存时间类型字段的分析
一:各种Date之间的转换方法 public class TimeTest { public static void main(String[] args) { Date date = new Dat ...
- Java日期时间处理
Java 日期时间处理 一.时间相关类 java.lang.System java.util.Date java.util.Calendar java.util.GregorianCalendar j ...
- Java日期时间,以及相互转换
Java日期时间,以及相互转化 package com.study.string; import java.text.ParseException; import java.text.SimpleDa ...
随机推荐
- SC用法
转自:(http://blog.163.com/yf_handsome/blog/static/20238174200802495124164/) SC使用这样的语法: 1. SC [Serverna ...
- Easy UI DataGrid 与 分页
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...
- LeetCode OJ:Climbing Stairs(攀爬台阶)
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- jquery.lazyload.js 图片延迟加载
当做网页的时候,特别是整个网页展示图片较多的时候,用到图片延迟效果是很好的 使用方法也非常简单. 1.在网页任何位置(一般是在</body>前面)加上如下代码(注意<script&g ...
- java事务(一)
Java中事务处理的基本方法与原理,包含以下文章: (一)Java事务处理的基本问题 (二)失败的案例 (三)丑陋的案例 (四)成功的案例(自己实现一个线程安全的TransactionManager) ...
- Java 代码规范,你应该知道的一些工具和用法
从事编程这个行业,你一定被别人说过或者说过别人这句话:代码要规范!求职面试时也能从 JD 上看到这个要求:要有良好的编程习惯.其实都是在讲代码规范(Code Style)这件事情. 每个人都有自己的编 ...
- EasyCMS在幼儿园视频直播项目实战中以redis操作池的方式应对高并发的redis操作问题
在之前的博客< EasyDarwin幼教云视频平台在幼教平台领域大放异彩!>中我们也介绍到,EasyCMS+EasyDarwin+redis形成的EasyDarwin云平台方案,在幼教平台 ...
- 特殊的 html 空格
http://www.zhangxinxu.com/wordpress/2015/01/tips-blank-character-chinese-align/
- iOS如何限制使用SDK的版本? 解决iOS项目的版本兼容问题
更新 2015-11-16 感谢微博好友@zyyy_000的评论,补充了为什么要在+ (void)load方法里面做Method Swizzling. 前言 最近,在做项目时,因为某种原因,突然要 ...
- python之List排序
sorted() #coding:utf-8 #sorted Ascending 升序 L = [12,23,43,3,65,34,21,3645] print(sorted(L)) >> ...