-
java 时间
- package com.grace.test;
-
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
-
- public class showDate {
- public static void main(String[] args) throws ParseException {
-
- Date d = new Date();
- String s = null;
-
-
- System.out.println(d);
-
-
- s = DateFormat.getDateInstance().format(d);
- System.out.println(s);
-
-
- s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
- System.out.println(s);
-
-
- s = DateFormat.getDateInstance(DateFormat.FULL).format(d);
- System.out.println(s);
-
-
- s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
- System.out.println(s);
-
-
- s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);
- System.out.println(s);
-
-
- DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- s = sdf.format(d);
- System.out.println(s);
-
-
- DateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
- s = sdf2.format(d);
- System.out.println(s);
-
-
- DateFormat sdf3 = new SimpleDateFormat("yyyyMMddHHmmss");
- s = sdf3.format(d);
- System.out.println(s);
-
-
- s = sdf.format(d);
- Date today = sdf.parse(s);
- System.out.println("字符串转成日期1:" + today);
- System.out.println("字符串转成日期2:" + sdf.format(today));
-
-
- Calendar c = Calendar.getInstance();
- System.out.println("年: " + c.get(Calendar.YEAR));
-
- System.out.println("月: " + (c.get(Calendar.MONTH) + 1) + "");
- System.out.println("日: " + c.get(Calendar.DAY_OF_MONTH));
- System.out.println("时: " + c.get(Calendar.HOUR_OF_DAY));
- System.out.println("分: " + c.get(Calendar.MINUTE));
- System.out.println("秒: " + c.get(Calendar.SECOND));
- System.out.println("当前时间毫秒数:" + c.getTimeInMillis());
- System.out.println("当前时间: " + c.getTime());
- }
- }
-
相关阅读:
理解Cookie和Session的区别及使用
数据库事务
Mybatis和hibernate的优缺点比较
MyBatis、JDBC相关知识
JVM学习笔记(一,待整理)
laravel运行url404错误
电影TS、TC、SCR、R5、BD、HD等版本是什么意思
mysql索引
双系统更改启动顺序
PHP Deprecated: Comments starting with '#' are deprecated in *.ini 警告解决办法
-
原文地址:https://www.cnblogs.com/xiaojiayu/p/5415768.html
Copyright © 2020-2023
润新知