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;

public class Main {
    /**
     * Transform Calendar to ISO 8601 string.
     */
    public static String dateToString(final Date date) {
        if (date == null) {
            return null;
        }

        String formatted = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US).format(date);
        return formatted.substring(0, 22) + ":" + formatted.substring(22);
    }
}