Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.util.Log;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    private static DateTime getDateFromISO(String ISOString) {
        //DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
        DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
        try {
            return parser.parseDateTime(ISOString);
        } catch (Throwable e) {
            try {
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
                df.setTimeZone(TimeZone.getTimeZone("UTC"));
                return new DateTime(df.parse(ISOString));
            } catch (Throwable ignored) {
                Log.d("ERROR", "Failed parsing string into date");
                e.printStackTrace();
            }
        }
        return null;
    }
}