Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 非标准日历的日期格式_Java_Android_Date Format - Fatal编程技术网

Java 非标准日历的日期格式

Java 非标准日历的日期格式,java,android,date-format,Java,Android,Date Format,我试图使用用户的日期格式配置来设置日期格式,但我使用的日历不是普通的公历,因此天数和年份完全不同。因此,我不能只将毫秒传递给DateFormat 我已经可以在我自己的日历中获得年、月、日,并格式化每个数字,但我必须硬编码日期样式。下面是我现在使用的代码: java.text.DateFormat timeFormat = DateFormat.getTimeFormat(MyApplication.getSharedApplication()); Locale currentLocal = My

我试图使用用户的日期格式配置来设置日期格式,但我使用的日历不是普通的公历,因此天数和年份完全不同。因此,我不能只将毫秒传递给DateFormat

我已经可以在我自己的日历中获得年、月、日,并格式化每个数字,但我必须硬编码日期样式。下面是我现在使用的代码:

java.text.DateFormat timeFormat = DateFormat.getTimeFormat(MyApplication.getSharedApplication());
Locale currentLocal = MyApplication.getSharedApplication().getResources().getConfiguration().locale;
JalaliCalendar calendar = new JalaliCalendar(new Date(unixTime));
return calendar.getJalalidate(currentLocal)+"  "+timeFormat.format(unixTime);


public String getJalalidate(Locale loc) {
    return String.format(loc, "%02d",year) + "/" + String.format(loc, "%02d",month) + "/" + String.format(loc, "%02d", date);
}
这是我的问题。我如何进一步微调,使YYYY/MM/DD不被硬编码


非常感谢

“因此,我不能将毫秒传递给DateFormat”-为什么不呢?它仍然是自Unix纪元以来的毫秒数,与日历无关
java.util.Date
与日历无关。您不能使用
SimpleDataFormat
(已指定日历)并传入相关模式吗?我不太确定这里的问题是什么…dateFormat.format(milis)将给出公历日期,而不管用户的语言环境如何。另外,我不想使用simpleDateFormat,因为我想使用用户选择的样式。如果您使用
dateFormat.setCalendar>为
dateFormat
指定日历系统,我就不想使用。我确实用一个扩展了calendar并实现了我自己的类来尝试过。但最终没有成功。我认为我没有正确的知识来实现一个完整的日历系统,大多数现成的代码处理日期转换,而不是完整的实现。我不知道你想要什么样的答案。与
DateFormat
一起使用不同日历的方法是使用
DateFormat.setCalendar
。如果您不打算实现一个完整的
日历
,您将无法使用该方法。。。