Java获取当前时间的年月日方法
来源:互联网 发布:大数据 政府治理 编辑:程序博客网 时间:2024/05/21 07:04
Java获取当前时间的年月日方法
- package com.ob;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- public class DateTest {
- public static void main(String[] args) throws ParseException {
- Calendar now = Calendar.getInstance();
- System.out.println("年: " + now.get(Calendar.YEAR));
- System.out.println("月: " + (now.get(Calendar.MONTH) + 1) + "");
- System.out.println("日: " + now.get(Calendar.DAY_OF_MONTH));
- System.out.println("时: " + now.get(Calendar.HOUR_OF_DAY));
- System.out.println("分: " + now.get(Calendar.MINUTE));
- System.out.println("秒: " + now.get(Calendar.SECOND));
- System.out.println("当前时间毫秒数:" + now.getTimeInMillis());
- System.out.println(now.getTime());
- Date d = new Date();
- System.out.println(d);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String dateNowStr = sdf.format(d);
- System.out.println("格式化后的日期:" + dateNowStr);
- String str = "2012-1-13 17:26:33"; //要跟上面sdf定义的格式一样
- Date today = sdf.parse(str);
- System.out.println("字符串转成日期:" + today);
- }
- }
0 0
- Java获取当前时间的年月日方法
- Java 获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- Java获取当前时间的年月日方法
- [Java] 获取当前时间的年月日的方法
- Java获取当前时间的年月日时分秒方法
- Java中获取当前时间的年月日方法
- linux正则表达式的运用
- intent基本用法
- Hadoop学习:Map/Reduce初探与小Demo实现
- Matlab实现字符串分割
- 使用 Django 和 Python 开发 Web 站点
- Java获取当前时间的年月日方法
- [leetcode 114] Flatten Binary Tree to Linked List
- CentOS6.3配置NFS服务
- 黑马程序员-多线程学习总结
- JAVA多线程
- CocoaPods安装和使用教程
- linux启动脚本和service、chkconfig
- python数据持久存储:pickle模块的基本使用
- MyMathLib系列(向量及矩阵--准备工作)