java时间格式转换

java时间格式转换时,是根据当前系统环境语言转换的,可不可以不根据系统环境转换,不管是中文系统,还是英文系统或者其它语言系统,都转成英文的。
Date d = new Date();
SimpleDateFormat s = new SimpleDateFormat("yyyy/MM/dd HH:mm a");
System.out.println(s.format(d));

2013/12/10 10:37 上午
上面的代码打印就是中文的,而我不管是什么语言都要英文的 2013/12/10 10:37 AM
有没有方法啊

实现思路就是先通过SimpleDateFormat方法定义一个时间类型的格式,之后SimpleDateFormat的format方法将一个符合时间格式的字符串匹配成对应的格式

举例:

String str0 = "2015年07月05日";

Date d1 = new SimpleDateFormat("yyyy年MM月dd日").parse(str0);//定义起始日期

SimpleDateFormat sdf0 = new SimpleDateFormat("yyyy");//定义一个只有年份的

SimpleDateFormat sdf1 = new SimpleDateFormat("MM");//月份的

SimpleDateFormat sdf2= new SimpleDateFormat("dd");//日的

String str1 = sdf0.format(d1);//取出特定日期d1的年份

String str2 = sdf1.format(d1);//取出特定日期d1的月份

String str3 = sdf2.format(d1);//取出特定日期d1的日

System.out.println("年份为:"+str1);

System.out.println("月份为:"+str2);

System.out.println("日为:"+str3);

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-10
指定SimpleDateFormat的Locale
SimpleDateFormat s = new SimpleDateFormat("yyyy/MM/dd HH:mm a");这句改成:

SimpleDateFormat s = new SimpleDateFormat("yyyy/MM/dd HH:mm a", Locale.ENGLISH);
就可以了本回答被提问者采纳
第2个回答  2013-12-10
 Date d = new Date();

  SimpleDateFormat s = new SimpleDateFormat("yyyy/MM/dd HH:mm a",Locale.ENGLISH);

  

  System.out.println(s.format(d));

第3个回答  2013-12-10
DateTime dt = Convert.ToDateTime("Oct. 20, 2004");
string result = dt.ToString("yyyy-MM-dd");
相似回答