Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.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 如何在android中显示日期格式?_Java_Android_Date_Simpledateformat - Fatal编程技术网

Java 如何在android中显示日期格式?

Java 如何在android中显示日期格式?,java,android,date,simpledateformat,Java,Android,Date,Simpledateformat,在我的android应用程序中 在这里,我想用以下格式显示日期,例如“21”是一个单独的字符串,月份是一个单独的字符串,年份是一个单独的字符串,而不使用字符串函数。有人能给出一些建议以这种格式转换吗?有任何日期函数可用吗?这是您需要的类: 链接中提供了示例,但简而言之,您首先需要解析日期,然后再次格式化日期。您需要查看用于解析日期字符串的类。为了在不使用字符串函数的情况下得到单独的字符串,您可能还需要为输出使用多个格式化程序。看起来有点像这样: String date="21-04-2013";

在我的android应用程序中
在这里,我想用以下格式显示日期,例如“21”是一个单独的字符串,月份是一个单独的字符串,年份是一个单独的字符串,而不使用字符串函数。有人能给出一些建议以这种格式转换吗?有任何日期函数可用吗?

这是您需要的类:


链接中提供了示例,但简而言之,您首先需要解析日期,然后再次格式化日期。

您需要查看用于解析日期字符串的类。为了在不使用字符串函数的情况下得到单独的字符串,您可能还需要为输出使用多个格式化程序。看起来有点像这样:

String date="21-04-2013";
如果要使用
String.split()
,则至少可以去掉上面代码段中的两个格式化程序

String date = "21-04-2013";
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy"); // input date
Date outDate = dateFormatter.parse(date);

SimpleDateFormat dayFormatter = new SimpleDateFormat("dd"); // output day
SimpleDateFormat monthFormatter = new SimpleDateFormat("MMM"); // output month
SimpleDateFormat yearFormatter = new SimpleDateFormat("yy"); // output year

String day = dayFormatter.format(outDate);
String monthy = monthFormatter.format(outDate);
String year = yearFormatter.format(outDate);