⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsimpledateformat.java

📁 由浅入深的介绍JAVAse的基本编程思想
💻 JAVA
字号:
import java.util.Date;
import java.util.Locale;
import java.text.SimpleDateFormat;

public class TestSimpleDateFormat{
	public static void main(String args[]){
		Locale locale1 = new Locale("zh","CN");
		Locale locale2 = new Locale("en","US");
		
		SimpleDateFormat sdf1 = new SimpleDateFormat();
		SimpleDateFormat sdf2 = new SimpleDateFormat(
			"yyyy/MM/dd hh:mm:ss");
		SimpleDateFormat sdf3 = new SimpleDateFormat(
			"yyyy/MM/dd hh:mm:ss E a z",locale1);
		SimpleDateFormat sdf4 = new SimpleDateFormat(
			"yyyy/MM/dd hh:mm:ss E a z",locale2);
		SimpleDateFormat sdf5 = new SimpleDateFormat(
			"yyyy年MM月dd日 E a HH点mm分ss秒");
		SimpleDateFormat sdf6 = new SimpleDateFormat(
			"'On 'yyyy-MM-dd HH' 0''clock,We tested it.'");
		
		Date d = new Date();
		System.out.println(sdf1.format(d));
		System.out.println(sdf2.format(d));
		System.out.println(sdf3.format(d));
		System.out.println(sdf4.format(d));
		System.out.println(sdf5.format(d));
		System.out.println(sdf6.format(d));
		
		try{
			d = sdf2.parse("2008/08/08 17:23:45");
			System.out.println(d);
			d = sdf5.parse("2007年04月17日 星期二 上午 10点02分54秒");
			System.out.println(d);
		}catch(java.text.ParseException e){
			e.printStackTrace();	
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -