java之时间格式
来源:互联网 发布:模糊c均值聚类算法 编辑:程序博客网 时间:2024/04/29 22:21
import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;public class MyDateFormat {public static void main(String[] args) {// 创建一个Date对象Date date =new Date();/** * 调用DateFormat类中的显示年月日时间的方法 * Dateformat是一个抽象类 不能直接创建对象 * 利用他的子类 已知子类只有SimpleDateFormat * */ /** * 获取格式器 =号后边为调用DateFormat的getInstance的方法获得DateFormat的子对象 */ DateFormat a1=DateFormat.getInstance(); /** * 获取其他格式器 * 该格式器具有默认语言环境的给定格式化风格 * */ DateFormat a2=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL) ; DateFormat a3=DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG) ; DateFormat a4=DateFormat.getDateTimeInstance(DateFormat.MEDIUM ,DateFormat.MEDIUM) ; DateFormat a5=DateFormat.getDateTimeInstance(DateFormat.SHORT ,DateFormat.SHORT); // DateFormat a5=DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL) ; /** * 格式器获得后 date转化为日期格式 * * */ System.out.println(a1.format(date)); System.out.println(a2.format(date)); System.out.println(a3.format(date)); System.out.println(a4.format(date)); System.out.println(a5.format(date)); // SimpleDateFormat 中有自定义输出日期格式的构造方法 SimpleDateFormat a6=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); /** * 调用format方法将 * a6.format(date) 将日期转化为字符串类型 * 调用了含参构造方法 * */ String str=a6.format(date); System.out.println(str); SimpleDateFormat a7=new SimpleDateFormat("MM-dd-yy"); String str1=a7.format(date); System.out.println(str1); }}
0 0
- java之时间格式
- java时间格式大全时间
- Foundation之时间格式
- 时间格式--java中的时间格式问题
- Java的时间格式
- Java时间格式转换
- java时间格式大全
- java学习时间格式
- JAVA时间格式大全
- java 时间格式
- java时间格式大全
- java时间格式大全
- java时间格式大全
- java时间格式大全
- java 时间格式
- java时间格式
- java时间格式大全
- java时间格式大全
- java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Sessio
- Redis常用几种数据类型
- 安装 Kali Linux 后需要做的 20 件事
- Intent和IntentFilter
- cmake:用add_subdirectory()添加外部项目文件夹
- java之时间格式
- Android 跟随手指移动的圆
- 不忘历史、维护中国海权
- 内存分配函数malloc calloc realloc
- BJOI2011 严格次小生成树
- Android四大基本组件介绍与生命周期
- phpmyadmin增加外键
- 桥接模式
- nginx 的日志记录 response 的报文头