Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
    /**
     * Parses XML datetime object to Date object
     *
     * @param xmlDateTime XML Datetime as a String
     * @return Datetime object
     * @throws ParseException if Parsing exception occurred
     */
    public static Date parseXmlDateTime(String xmlDateTime) {
        Date parsedDate = new Date();
        try {
            xmlDateTime = xmlDateTime.replace("Z", "+0000");
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault());
            parsedDate = dateFormat.parse(xmlDateTime);
            return parsedDate;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return parsedDate;
    }
}