1.Date类:  https://www.cnblogs.com/huangminwen/p/5994927.html

2.DateFormat和SimpleDateFormat (simple简单的)

DateFormat类

此类是一个日期的格式化类,用来格式化日期。具体日期可以通过java.util.Date类来获取。

DateFormat类的定义:此类是定义在java.test包中的。

public abstract class DateFormat extends Format1

实例化DateFormat

DateFormat是一个抽象类,按照以住的思路,直接使用其子类实例化即可。但是DateFormat 类本身的内部提供了可以直接为其实例化的操作。

//得到日期的DateFormat对象: public static final DateFormat getDateInstance();

//得到日期时间的DateFormat对象: public static final DateFormat getDateTimeInstance();

//使用DateFormat类格式化Date类日期 public final String format(Date date)

SimpleDateFormat类使用

在构造对象时要传入日期格式模板

//构造方法: public SimpleDateFormat(String pattern)

//转换: public Date parse(String source)throws ParseException //-->此时取得的是全部时间数。

//格式化: public final String Format(Date date) //-->将时间重新格式化成字符串显示。

 import java.text.SimpleDateFormat;
import java.util.Date; public class Lianxi { public static void main(String[] args) {
SimpleDateFormat date1 = new SimpleDateFormat("yy/MM/dd");
Date now = new Date();
SimpleDateFormat date2 = new SimpleDateFormat(
"一年中的第 D 天 一年中第w个星期 一月中第W个星期 在一天中k时 z时区");
System.out.println(date1.format(now));//19/02/03
System.out.println(date2.format(now));//一年中的第 34 天 一年中第6个星期 一月中第2个星期 在一天中15时 CST时区
System.out.println(now.toGMTString());//格林时间-3 Feb 2019 07:02:48 GMT
System.out.println(now.toLocaleString());//2019-2-3 15:02:48
System.out.println(now.toString());//Sun Feb 03 15:02:48 CST 2019
}
}

String和Date的转换

 import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner; public class TestDateFommat {
public static void main(String[] args) throws ParseException {
DateFormat d=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
/**Date-->String format(Date d)
* String-->Date parse(String s)*/
Date date=new Date(12318231233123L);
System.out.println(date);
String strDate=d.format(date);
System.out.println(strDate); Scanner input=new Scanner(System.in);
System.out.println("请输入一个时间:yyyy-MM-dd HH:mm:ss.SSS");
String str=input.nextLine();
Date d2=d.parse(str); System.out.println(d2);
}
}

3.日历类 Calendarhttps://www.cnblogs.com/huangminwen/p/6041168.html

最新文章

  1. 使用NW.js封装微信公众号菜单编辑器为桌面应用
  2. Git相关文章
  3. SQL Server:“数据收缩”详解
  4. 虚拟机中如何Linux系统如何访问PC硬盘中的文件(如何将windows下的文件夹挂载到linux虚拟机下)
  5. 盛希泰:办公室就像男人的春药——人的一生的精力是有限的,你把有限的时间分配给谁决定你的成败——你有N多选择,你人生的积累就是N多选择加起来的结果
  6. Java面试题集(136-150)
  7. linux cat more less head tail
  8. js函数验证方式:验证是否是数字,支持小数,负数
  9. zabbix优化,配合文件,zabbix_get命令
  10. ibatis项目启动报错The string "--" is not permitted within comments【原】
  11. MyBatis - 10.MyBatis扩展
  12. [HDU3726]Graph and Queries
  13. servlet 中处理 json 请求,并访问 service 类,返回处理结果
  14. SQL Server 之 附加数据库出现“ 拒绝访问 ”
  15. eclipse 自动生成json格式的toString()方法
  16. Django基础九之中间件
  17. POJ2195:Going Home(费用流入门)
  18. [吴恩达机器学习笔记]13聚类K-means
  19. Ubuntu16.04安装印象笔记
  20. InnoSetup 打包Winform程序

热门文章

  1. centos7.4+mysql5.6+virtualenv+python3.6+nginx+uwsgi+django生产环境搭建
  2. csharp: using HtmlAgilityPack and ScrapySharp reading Url find text
  3. webpack单独打包一个less文件
  4. VUE CLI 3.0 项目引入 ElementUI
  5. Java并发编程(四)synchronized
  6. unicode编码和utf8编码的区别
  7. (网页)the server responded with a status of 403 (Forbidden)
  8. MySQL复制ERROR 1794 (HY000): Slave is not configured or failed to initialize properly.
  9. [cb]ScriptableWizard 创建向导
  10. 11LaTeX学习系列之---LaTeX的特殊字符