Asked  2 Years ago    Answers:  5   Viewed   4.6k times

How do I can parse this date 2018-01-09T11:11:02.0+03:00 to dd.MM.yyyy hh:mm format in Android?

And what does T between 09 and 11 mean? Thanks.

I don't know how the back-end developer got this format. I am using Java.



If you are using java, you can use SimpeDateFormat with patterns:

        String date = "2018-01-09T11:11:02.0+03:00";
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
        SimpleDateFormat output = new SimpleDateFormat("dd.MM.yyyy hh:mm");
        Date d = null;
        try {
            d = dateformat.parse(date /*your date as String*/);
        } catch (ParseException e) {
        String formattedDate = output.format(d);

        Log.d("Date format", "output date :" + formattedDate);

The output is :

D/Date format: output date :09.01.2018 09:11

EDIT : Thanks to @OleV.V., for API > 26, or using ThreeTenABP we can use

DateTimeFormatter, we can do something like that

    String date = "2018-01-09T11:11:02.0+03:00";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
    DateTimeFormatter formatterOut = DateTimeFormatter.ofPattern("dd.MM.yyyy hh:mm");
    LocalDate parsedDate = LocalDate.parse(date, formatter);

    String formattedDate = formatterOut.format(parsedDate);
    Log.d("Date format", "output date :" + formattedDate);
Monday, September 19, 2022
function (startDate, endDate, addFn, interval) {

 addFn = addFn || Date.prototype.addDays;
 interval = interval || 1;

 var retVal = [];
 var current = new Date(startDate);

 while (current <= endDate) {
  retVal.push(new Date(current));
  current =, interval);

 return retVal;

Friday, September 2, 2022

Excuse me for mentioning it, I suspect that there is no problem in your code, there’s only confusion. If you think the old Date class is behaving confusingly, allow me to be the first of many to agree with you. The good and sound solution to this problem is you stop using Date and start using the modern Java date and time API instead.

Since you are coding for Android, you first step is to get the ThreeTenABP, the library for Android that offers the modern API (if you were using Java 8 or 9, you could skip this step since the modern API wold be built in). The details are described in this question: How to use ThreeTenABP in Android Project. Now you can do:

    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss Z");
    String dateUTCAsString = "2017-11-15T12:54:25 +0000";
    Instant dateResult = OffsetDateTime.parse(dateUTCAsString, formatter).toInstant();

On my computer this just printed:


The Z at the end means Zulu time zone or UTC.

As you may know, System.out.println(dateResult) implicitly calls the toString method of the dateResult object. Objects of the class Instant produce the above format, always in UTC, as I understood you wanted. The Instant class is the natural replacement for the old-fashioned Date class for most purposes. Internally the Instant holds the number of seconds and nanoseconds since the epoch, which is defined as January 1 1970 at 0:00 midnight UTC. I encourage you to consider this an irrelevant implementation detail. An Instant is a point on the time-line.

What went wrong?

You asked for a date in UTC. Depending on how you look at it, you can or cannot have this.

  • On one hand a Date is implemented as the number of seconds and milliseconds since the epoch, so if you use the above definition of the epoch, you may say that it is always in UTC.
  • On the other hand you shouldn’t worry about implementation details. Conceptually a Date (like an Instant) is a point on the time-line, and does not and cannot have a time zone or offset; it cannot be in UTC. To make matters more confusing, when you do "getCurrentDateUTC: dateResult = " + dateResult, then dateResult.toString() is implicitly called. This method grabs your JVM’s time zone setting and converts the date-time to this zone and uses it for the generated string (without modifying the Date object). This is why you will see the time in EET on your computer or device no matter which Date you try to print.

java.time or JSR-310

The modern date and time API is know as java.time or JSR-310. One good source for learning to use it is the Oracle tutorial.

Saturday, November 19, 2022

To override the DatePicker format the best bet would be to override one of its constructors with a slight edit to the original code. You can edit the ViewGroup in code for you but I'd seriously consider not doing it that way.

  1. Create class LocalizedDatePicker
  2. Override public DatePicker (Context context, AttributeSet attrs, int defStyle), android.util.AttributeSet, int)
  3. Copy the code from the original DatePicker constructor (you may need to select a different branch after some testing, I have linked the head)
  4. Override methods that call reorderSpinners() to remove that call.
  5. Replace line inflater.inflate(R.layout.date_picker, this, true); with inflater.inflate(my.package.R.layout.localized_date_picker, this, true);
  6. Copy the original date_picker.xml layout to your local resource localized_date_picker.xml
  7. Edit the file for the desired order, since you're editing this please respect the localization of other places and keep a copy of the original in your global layout folder and put the localized_date_picker.xml in your region specific folder. Since the system's layout is Month Day Year people in other places may expect that order.
Monday, October 17, 2022

I tried it with 30/01/2010


and then I put in

=TEXT(B1, "yyyy-mm-dd").

The result was expected.

I suspect the issue is the cell you are doing this too is not in date format.

For example, if I change my value to 30.01.2010 then the value is then duplicated (in the same manner you describe)

Or, you could keep it as

=TEXT(A1, "yyyy-mm-dd")

And update all the . to / with a quick macro

Option Explicit
Sub ReplaceDate()

Dim row As Integer
row = 1

Do While (Range("A" & row).Value <> "")

    Dim val As String
    val = Range("A" & row).Value

    Dim i As Integer

    Dim result As String
    result = ""

    Dim spl() As String
    spl = Split(val, ".")

    If (UBound(spl) > 0) Then

    For i = 0 To Len(val)

    Dim r As String
        result = result & Replace(Mid(val, i + 1, 1), ".", "/")
    Next i

    End If

    If result <> "" Then

        Range("A" & row).NumberFormat = "@"
        Range("A" & row).Value = result

    End If

row = row + 1

End Sub

How do I add VBA in MS Office?

Saturday, November 19, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :

Browse Other Code Languages