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.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static SimpleDateFormat mZuluFormat;

    public static String formatString(String dateString) {
        try {
            return dateToString(getDate(dateString));
        } catch (Exception e) {
            return "";
        }
    }

    public static String dateToString(Date date) {
        try {
            return (new SimpleDateFormat("MM/dd/yyyy")).format(date);
        } catch (Exception ex) {
            return null;
        }
    }

    public static Date getDate(String dataString) {
        try {
            if (dataString == null || dataString.isEmpty()) {
                return null;
            }
            return getZuluFormat().parse(dataString);
        } catch (Exception ex) {
            return null;
        }
    }

    public static DateFormat getZuluFormat() {
        if (mZuluFormat == null) {
            //Format used by SharePoint for encoding datetimes
            mZuluFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
            mZuluFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        }
        return mZuluFormat;
    }
}