(1)String类格式化当前日期
2013-06-16 10:09
183 查看
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);
}
}
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);
}
}
相关文章推荐
- Java使用String类格式化当前日期实现代码
- Java使用String类格式化当前日期
- String类格式化当前日期
- Java使用String类格式化当前日期
- 字符串处理技术之格式化字符串(String类格式化当前日期)
- Java使用String类格式化当前日期
- 【转载】mysql 获取当前日期及格式化
- mysql 获取当前日期及格式化
- PHP获取当前日期和时间及格式化方法参数
- python当前时间,日期格式化,字符串日期互转
- 使用Smarty 获取当前日期时间和格式化日期时间的方法详解
- mysql 获取当前日期及格式化
- JS日期,JS获取当前日期时间,js日期格式化
- js-格式化当前日期
- mysql 获取当前日期及格式化
- MySQL取得当前时间的函数是什么 格式化日期的函数是什么
- java 获取当前日期并且格式化输出
- JS获取当前日期和时间的方法,并按照YYYY-MM-DD格式化
- Swift教程_基础技术(0002)_获取当前日期时间、日期时间格式化及转换
- mysql 获取当前日期及格式化