提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用SimpleDateFormat格式化年份
/** 来 自 NowJava.com - 时代Java**/ import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static void main(String[] args) { Date date = new Date(); //formatting year in yy format like 07, 08 etc String strDateFormat = "yy"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); System.out.println("Current year in yy format : " + sdf.format(date)); /* *来 自 n o w j a v a . c o m */ //formatting year in yyyy format like 2007, 2008 etc. strDateFormat = "yyyy"; sdf =