What i'm wanting to do is format the string 08-18 15:00
to read 18-08-12 15:00
. How do I convert it into a date format it and the convert back to a string so i can use to setText to a textview?
Asked
Active
Viewed 371 times
1

Luke Batley
- 2,384
- 10
- 44
- 76
-
1The year portion of your date is missing. It is always 12? – Anirudh Ramanathan Jul 17 '12 at 13:19
-
hi yeah it should say 2012-08-18 15:00 however for some reason it's not saving my edits to my question – Luke Batley Jul 17 '12 at 13:22
-
What about using [`SimpleDateFormat`](http://developer.android.com/reference/java/text/SimpleDateFormat.html)? – Lion Jul 17 '12 at 13:23
2 Answers
4
This is what you are looking for. You have to use SimpleDateFormat
.
Here is the link: String to date conversion

Community
- 1
- 1

pixelscreen
- 1,945
- 2
- 18
- 40
2
Of course, using SimpleDateFormat would be better solution, but if you insist and if you know coming style... Then you can simply format it yourself, with some codes like this:
public static String ConvertDate(String valueToFormat) {
String value = valueToFormat;
String day = value.substring(value.indexOf("-") + 1, value.indexOf(" "));
String month = value.substring(0, value.indexOf("-"));
String time = value.substring(value.indexOf(" ") + 1, value.lenght());
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
// if you want year to appear as only last two items
year = year % 100;
value = day + "-" + month + "-" + year + " " + time;
return value;
}

yahya
- 4,810
- 3
- 41
- 58