---
title: "How to convert date string in another string?"  
description: "How to convert date string in another string?"  
author: "Anonymous User"  
published: 2014-10-14  
updated: 2014-10-14  
canonical: https://www.mindstick.com/forum/2383/how-to-convert-date-string-in-another-string  
category: "android"  
tags: ["android", "mobile development"]  
reading_time: 2 minutes  

---

# How to convert date string in another string?

How can I [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) from "2014-10-13T10:41:22.863+08:00" into "2014-10-13 10:41"?

I have [failed](https://www.mindstick.com/forum/160484/error-failed-to-launch-debug-adapter-additional-information-may-be-available-in-the-output-window) to do so:

```
String date = "2014-10-13T10:41:22.863+8:00";SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");Date dateTime = null;try {    dateTime = dateFormat.parse(date);} catch(ParseException e) { ... }System.out.printf(dateTime.toString());
```

through : ParseException 2014-10-13T10:41:22.863+8:00\

## Replies

### Reply by Anonymous User

If you don't need to do some operation/manipulation on the Date before printing it in correct format, then you can just directly transform the string into yyyy-MM-dd HH:mm with this:\

```
String date = "2014-10-13T10:41:22.863+8:00";date = date.substring(0, 16);  // 2014-10-13T10:41, remove value after minutesdate = date.replace("T", " "); // 2014-10-13 10:41, replace the 'T' characterSystem.out.println(date);      // 2014-10-13 10:41Else, if you want to parse it beforehand, then change the pattern to yyyy-MM-dd'T'HH:mm (note the additional of string constant 'T').String date = "2014-10-13T10:41:22.863+8:00";// parse the String to DateSimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");Date dateTime = null;try {    dateTime = sourceFormat.parse(date);} catch (ParseException e) {    e.printStackTrace();}System.out.println(dateTime.toString()); // Mon Oct 13 10:41:00 SGT 2014// print the Date in expected format
```

SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");System.out.println(targetFormat.format(dateTime)); // 2014-10-13 10:41The reason you got ParseException is because the format you use to parse (yyyy-MM-dd HH:mm) is not the same as the source (yyyy-MM-dd'T'HH:mm ...). Your SimpleDateFormatter expected whitespace instead of character 'T' after the date.

### Reply by Anonymous User

Try this way,hope this will help you to solve your problem.

The Z at the end is usually the timezone offset. If you you don't need it maybe you can drop it on both sides.

```
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");try{    Date d = df1.parse("2014-10-13T10:41:22.863+8:00");    System.out.println("new date format " + df2.format(d));}catch(Exception e){   e.printStackTrace();}
```


---

Original Source: https://www.mindstick.com/forum/2383/how-to-convert-date-string-in-another-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
