java dateformat_Java中的DateFormat用法
importjava.util.Date;importjava.text.DateFormat;/*** 格式化时间类 DateFormat.FULL = 0 DateFormat.DEFAULT = 2 DateFormat.LONG = 1
* DateFormat.MEDIUM = 2 DateFormat.SHORT = 3*/
public classTest {public static voidmain(String[] args) {
Date d= newDate();
String s;/**Date类的格式: Sat Apr 16 13:17:29 CST 2006*/System.out.println(d);
System.out.println("******************************************");/**getDateInstance()*/
/**输出格式: 2006-4-16*/s=DateFormat.getDateInstance().format(d);
System.out.println(s);/**输出格式: 2006-4-16*/s=DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);
System.out.println(s);/**输出格式: 2006年4月16日 星期六*/s=DateFormat.getDateInstance(DateFormat.FULL).format(d);
System.out.println(s);/**输出格式: 2006-4-16*/s=DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
System.out.println(s);/**输出格式: 06-4-16*/s=DateFormat.getDateInstance(DateFormat.SHORT).format(d);
System.out.println(s);/**输出格式: 2006-01-01 00:00:00*/java.text.DateFormat format1= newjava.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
s= format1.format(newDate());
System.out.println(s);/**输出格式: 2006-01-01 01:00:00*/System.out.println((newjava.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(newDate()));/**输出格式: 2006-01-01 13:00:00*/System.out.println((newjava.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(newDate()));/**输出格式: 20060101000000 ***/java.text.DateFormat format2= newjava.text.SimpleDateFormat("yyyyMMddhhmmss");
s= format2.format(newDate());
System.out.println(s);
}
}
attention:注意下,月份是从0开始的,要Calendar.MONTH+1才可以的
Calendar cal=Calendar.getInstance();
cal.setTime(newDate());
System.out.println("System Date: " + cal.get(Calendar.MONTH + 1));
java dateformat_Java中的DateFormat用法相关推荐
- Java程序中Timer的用法
Java程序中Timer的用法 import java.io.IOException; import java.util.Timer; public class CheckTimer {/*** @p ...
- java stream中Collectors的用法
文章目录 简介 Collectors.toList() Collectors.toSet() Collectors.toCollection() Collectors.toMap() Collecto ...
- java项目中enum的用法_java中enum的用法
本文实例讲述了java中enum的用法.分享给大家供大家参考.具体分析如下: 1. 基本用法 enum Day { SUNDAY, MONDAY, TUESDAY, WENDSDAY, THURSDA ...
- java jna_Java中jna的用法
(1)jna是对jni的封装,让java使用者能更好的使用本地的动态库 (2)使用jna需要下载jna的jar包,该jar包就是对jni的封装,所以在调用效率上来讲,jna是要比jni低一点的,不过对 ...
- java中dateFormat是什么_Java中的DateFormat用法举例
觉得这个DateFormat是比较实用,记录一下,文章来自csdn博客中的一个名叫空心兜兜的网友. class="java"> import java.util.Date; ...
- java stringtoarray_java中toArray()的用法
一直不太熟悉toarray()的用法 现整理如下 一.Incident public static void main(String[] args) { List list = new ArrayLi ...
- java new_Java中new的用法
Java语言中,new的作用是为一个对象(Object)分配内存,代码清单1-1说明了为各种Object分配内存的方法. 代码清单1-1 为各种Object分配内存的方法 int a = 20; ...
- java typeof_js中typeof的用法汇总
JavaScript中的typeof其实非常复杂,它可以用来做很多事情,但同时也有很多怪异的表现.本文列举出了它的多个用法,而且还指出了存在的问题以及解决办法. > typeof undefin ...
- java string中indexOf()常用用法
Java中字符串中子串的查找共有四种方法,如下: 1.int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引. 2.int indexOf(String st ...
最新文章
- Angular 组件交互
- 和李洪强一起学设计01 PS第一天
- cylance做的机器学习相关材料汇总
- 机器学习笔记(五)神经网络
- Could not resolve all dependencies for configuration ':app:_debugApk'
- proteus里面没有stm32怎么办_嵌入式单片机之stm32串口你懂了多少!!
- 头条鼓励内容营销吗?创作商品营销内容会不会限制推荐?
- 【干货】基于注意力机制的seq2seq网络
- 按键精灵修改计算机名,最新按键精灵脚本代码大全 按键精灵命令运行方法
- python求解二次规划问题
- 通信尾纤常用尾纤简介
- 安国主控,U盘量产,起死回生
- c51单片机流水灯程序汇编语言,单片机流水灯汇编程序,8路流水灯汇编语言程序的写法...
- 常见的反爬策略及解决方案
- JS 替换字符串中指定字符
- mysql程序设计考试app_MySQL数据库设计与应用知到APP期末考试完整答案
- [SiFi]三体中英名词翻译chapter1-3
- 机器学习结果指标评估
- 全球及中国水疗水下跑步机行业研究及十四五规划分析报告
- 朱光潜给青年的十二封信 之 谈升学和选课