Date of time object from a web service displayed in Android text mode with a drawing?

Hi, I have a web service that returns a date object like this, as a Json return

"/Date(922312800000+0200)/" 

However, I need to show it in text form in this template

 "19.12.2011 16:15" 

How can I convert this return to this template?

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

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

Edit: Here is the code that works 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
source share
2 answers

It seems to me that your date has been given in milliseconds since 1970, so something like this:

 // 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. 
+1
source

You need to use: DateFormat .

A simple example:

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

Source: https://habr.com/ru/post/1446748/


All Articles