import java.text.DateFormat;

import java.text.SimpleDateFormat;

---------------------------------------------------------------------------------

DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

Date d = new Date(12436432737L);

String s = df.format(d);  /* 将时间对象转换成字符串,按照("yyyy-MM-dd hh:mm:ss")格式 */

System.out.println(s);

---------------------------------------------------------------------------------

String s2 = "1994-8-29";

DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");

try {

  Date d2 = df2.parse(s2);  /* 将字符串转换成时间对象,字符串格式必须和("yyyy-MM-dd")相同,否则出现异常 */

  System.out.println(d2);

} catch (ParseException e) {

  e.printStackTrace();

}

DateFormat and SimpleDateFormat的更多相关文章

  1. 详解Java中格式化日期的DateFormat与SimpleDateFormat类

    DateFormat其本身是一个抽象类,SimpleDateFormat 类是DateFormat类的子类,一般情况下来讲DateFormat类很少会直接使用,而都使用SimpleDateFormat ...

  2. DateFormat与SimpleDateFormat区别和使用详解

    DateFormat类 此类是一个日期的格式化类,用来格式化日期.具体日期可以通过java.util.Date类来获取. DateFormat类的定义:此类是定义在java.test包中的. publ ...

  3. 时间日期相关类:Date类,DateFormat类&SimpleDateFormat类,Calendar类

    日期相关类 1.Date类:日期时间类 A.构造方法 Date(): 根据当前系统时间创建日期对象 ​ Date(Long time):根据传入的毫秒值时间创建日期对象 B.成员方法 Long get ...

  4. Date、DateFormat、SimpleDateFormat、Calendar

    package com.Date; import java.util.Date; /* * Date 表示特定的瞬间,精确到毫秒 * JDK1.0开始 * 构造方法(常用的方法,过时的不管): * D ...

  5. Date、Calendar、DateFormat、SimpleDateFormat、Timer、TimerTask类

    类 Date 在 JDK 1.1 之前,类 Date 有两个其他的函数.它允许把日期解释为年.月.日.小时.分钟和秒值. 它也允许格式化和解析日期字符串.不过,这些函数的 API 不易于实现国际化.从 ...

  6. SimpleDateFormat转换时间格式

    SimpleDateFormat有两个常用的方法parse和format 其中SimpleDateFormat在创建时有一下集中格式可以选择 SimpleDateFormat sdf = new Si ...

  7. java 中的SimpleDateFormat、Date函数以及字符串和Date类型互转

    SimpleDateFormat是一个以与语言环境有关的方式来格式化和解析日期的具体类.它允许进行格式化(日期 -> 文本).解析(文本 -> 日期)和规范化. SimpleDateFor ...

  8. javaWEB国际化:DateFormat,NumberFormat,MessageFormat,ResourceBundle的使用

    DateFormat:格式化日期的工具类,本身是一个抽象类: NumberFormat:格式化 数字 到 数字字符串,或货币字符串的字符类; MessageFormat: 可以格式化模式字符串,模式字 ...

  9. SimpleDateFormat格式化日期

    SimpleDateFormat格式化日期 import java.text.SimpleDateFormat;import java.util.Date;public class test { pu ...

随机推荐

  1. codecombat之地牢关卡Python代码

    1.地牢 # 向宝石进发. # 小心撞墙! # 在下面输入你的代码. self.moveRight() self.moveDown() self.moveRight() 2.深藏的宝石 # 利用你的移 ...

  2. 轮播插件swiper

    使用步骤 1.引用js <script src="swiper/swiper.min.js" type="text/javascript" charset ...

  3. 解决npm ERR! Unexpected end of JSON input while parsing near的方法

    这两天执行 npm install 时会报错误: npm ERR! Unexpected end of JSON input while parsing near 清除cache npm cache ...

  4. Quartz.Net进阶之五:TriggerListener 、JobListener 和 SchedulerListener

    一.介绍 今天开始学习监听器,就是 Listener,在Quartz.Net 中,主要包含3类的监听器,主要内容包括:TriggerListener .JobListener 和 SchedulerL ...

  5. js兼容公用方法

    var utils = (function(){ //把类数组转换为数组(兼容所有的浏览器) function toArray(classAry){ var ary = []; try { ary = ...

  6. sha1 算法源码

    原来指望sha1 这种烂大街的算法 不会出什么幺蛾子 结果<linux C编程实战Code>bt章节的sha1 代码 我在linux和windows下的结果不一样 然后用了哈希工具查看了下 ...

  7. 纯css实现无限嵌套菜单

    效果图: demo:关键的地方都以颜色明显标识 <!DOCTYPE html> <html> <head> <title>menu</title& ...

  8. IIS Express(7.0) HTTP 错误 500.22 - Internal Server Error(vs2013)

    1.错误如下: HTTP 错误 500.22 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设置. 解决的方法: 首先,找到本地appcmd.x ...

  9. @无痕客 https://www.cnblogs.com/wuhenke/archive/2012/12/24/2830530.html 通篇引用

    无痕客 https://www.cnblogs.com/wuhenke/archive/2012/12/24/2830530.html 关于Async与Await的FAQ 关于Async与Await的 ...

  10. 关于Eclipse的一些简单设置

    1.加入eclipse没有编辑的文件 例如:想用html类型打开*.jetx文件,在window-preferences-General-Content Types-Text-Html加入*.jetx ...