(1)String类格式化当前日期

来源:互联网 发布:杨幂和唐嫣友情知乎 编辑:程序博客网 时间:2024/05/24 07:37
import java.util.Date;
import java.util.Locale;
public class Example {
public static void main(String[] args)
{
Date today=new Date();
String a=String.format(Locale.US,"%tb",today );//格式化后的字符串为对月份的英文缩写
System.out.println("格式化后的字符串为月份的英文缩写:"+a);
String b=String.format(Locale.US,"%tB",today);//格式化后的字符串为月份的英文全写
System.out.println("格式化后的字符串为英文的全写"+b);
String c=String.format("%ta", today);//格式化后的字符串为星期(如星期一)
System.out.println("月格式化后的字符串为星期:"+c);
String d=String.format("%tA", today);//格式化后的字符串为星期(如星期二)
System.out.println("格式化后的字符串为星期:"+d);
String e=String.format("%tY", today);//格式化后的字符串为4位的年份值
System.out.println("格式化后的字符串为4位年份值"+e);
String f=String.format("%ty",today);//格式化后的年份为两位的年份值
System.out.println("格式化后的年份为两位的年份值"+f);
String g=String.format("%tm", today);//格式化后的字符串为2位的月份值
System.out.println("格式化后的字符串为2位的月份值"+g);
String h=String.format("%td",today);//格式化后的字符串为两位的日期值
System.out.println("格式化后的字符串为2位的日期值"+h);
String i=String.format("%te",today);//格式化后的字符串为1位的字符串
System.out.println("格式化后的字符串为1位的日期值 "+i);
}