日期时间对象从webservice显示在Android textview与模式?

时间:2023-01-17 19:26:22

Hi I have web service that return a date object like this as a return of the Json

你好,我有一个web服务,它返回一个像这样的日期对象作为Json的返回

 "/Date(922312800000+0200)/"

However i need to show it on the textview in this pattern

但是我需要在这个模式的textview中显示它

"19.12.2011 16:15" 

how can I convert that return to this pattern ?

如何将返回转换为这个模式?

Edit : Here is my code still giving java.lang.IllegalArgumentException

编辑:我的代码仍然给出java.lang.IllegalArgumentException

SimpleDateFormat date = new SimpleDateFormat("dd/MM/yy");
String dateText = date.format(tempEntry.getCreatedDate());

Edit : Here is the code that work for me

编辑:这是为我工作的代码。

String dateText = tempEntry.getCreatedDate();
String dateString = dateText.replace("/Date(", "").replace(")/", "");
String[] dateParts = dateString.split("[+-]");
Date dateFormat = new Date(Long.parseLong(dateParts[0]))

2 个解决方案

#1


1  

It appears to me that your Date is given in milliseconds from 1970, so, something like that:

在我看来,你的日期是以1970年开始的毫秒为单位的,所以,大概是这样:

// remove the unneeded information
String date = date.replace("/Date(", "").replace(")/"); 
String[] dateParts = date.split("[+-]")
//get the date represented by the given millis
Calendar c = Calendar.getInstance();
c.setTime(Long.parseLong(dateParts[0]);
// proceed with formatting to the desired date format.

#2


1  

You need to use: DateFormat.

您需要使用:DateFormat。

Simple example:

简单的例子:

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String today = formatter.format(date);
textView.setText("Today : " + today);

#1


1  

It appears to me that your Date is given in milliseconds from 1970, so, something like that:

在我看来,你的日期是以1970年开始的毫秒为单位的,所以,大概是这样:

// remove the unneeded information
String date = date.replace("/Date(", "").replace(")/"); 
String[] dateParts = date.split("[+-]")
//get the date represented by the given millis
Calendar c = Calendar.getInstance();
c.setTime(Long.parseLong(dateParts[0]);
// proceed with formatting to the desired date format.

#2


1  

You need to use: DateFormat.

您需要使用:DateFormat。

Simple example:

简单的例子:

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String today = formatter.format(date);
textView.setText("Today : " + today);