如何在Java中将日本日期转换为西方日期?

4
我有以下这些方法:

我有以下这些方法:

//datetime is millisecond
public static String getStringDateFormatMonth(long datetime) {
          String yearlessPattern = "yyyy年MM月";
          SimpleDateFormat yearlessSDF = new SimpleDateFormat(yearlessPattern);
          Date date = new Date(datetime);
          String datestr = yearlessSDF.format(date);
          return datestr;

         }

public static String getStringDateFormat(long datetime) {
          String yearlessPattern = "dd日";
          SimpleDateFormat yearlessSDF = new SimpleDateFormat(yearlessPattern);
          SimpleDateFormat sdfDay = new SimpleDateFormat("E", Locale.JAPAN);
          Date date = new Date(datetime);
          String datestr = yearlessSDF.format(date) + "(" + sdfDay.format(date) + ")";
          return datestr;

         }

初始化字符串a:

String a = LifelogUtil.getStringDateFormatMonth(currentDate.getTimeInMillis())
                    + LifelogUtil.getStringDateFormat(currentDate.getTimeInMillis());

我得到的结果是:
2015年07月19日(日)

现在我想将这个日期转换回西方日期,格式为“yyyy-MM-dd”,但我不知道该怎么做。请帮帮我!谢谢!
3个回答

2
您提供的格式是日本的本地格式,因此您可以使用默认选项。为了方便起见,请参考Java文档http://docs.oracle.com/javase/7/docs/api/java/text/DateFormat.html。请尝试这个。
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, new Locale("ja"));
System.out.println(df.parse("2015年07月20日"));
System.out.println(df.format(new Date()));

输出应该像这样:
Mon Jul 20 00:00:00 IST 2015
2015年07月20日

请参考之前在ideone发布的答案 IDEONE


2
今日免费次数已满, 请开通会员/明日再来
    // use an object internally:
    Date anyDate = new Date();

    // can also be SimpleDateFormat, etc:
    DateFormat japaneseDf = DateFormat.getDateInstance(DateFormat.FULL, Locale.JAPAN);
    DateFormat germanDf = DateFormat.getDateInstance(DateFormat.FULL, Locale.GERMANY);

    // when you need to display it somewhere render it appropriately, not changing the data:
    System.out.println(japaneseDf.format(anyDate));
    System.out.println(germanDf.format(anyDate));

打印输出:
2015年7月20日 (月曜日)
Montag, 20. Juli 2015

0

这应该会有所帮助。

        SimpleDateFormat jp= new SimpleDateFormat("yyyy年MM月dd日(E)",Locale.JAPAN); //Japan Format
        SimpleDateFormat west = new SimpleDateFormat("yyyy-MM-dd"); //Western Format
        try{
            Date date = jp.parse(a); //convert the String to date
            System.out.println(west.format(date));//format the date to Western 
        }catch (Exception ex){
            System.out.println(ex.getMessage());
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接