Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Locale;

import java.util.TimeZone;

public class Main {
    public static Date ConvertFromWebService(String strDate) {
        String[] formats = new String[] { "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
                "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" };
        for (String frm : formats) {
            try {
                SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US);
                format.setTimeZone(TimeZone.getTimeZone("UTC"));
                return format.parse(strDate);
            } catch (Exception ex) {
            }
        }
        return null;
    }
}