Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    /**
     * Parse a time character array as defined in PKCS#11 and return is as a
     * Date object.
     *
     * @param timeChars A time encoded as character array as specified in PKCS#11.
     * @return A Date object set to the time indicated in the given char-array.
     *         null, if the given char array is null or the format is wrong.
     * @preconditions
     * @postconditions
     */
    public static Date parseTime(char[] timeChars) {
        Date time = null;

        if ((timeChars != null) && timeChars.length > 2) {
            String timeString = new String(timeChars, 0, timeChars.length - 2);
            try {
                SimpleDateFormat utc = new SimpleDateFormat("yyyyMMddhhmmss");
                utc.setTimeZone(TimeZone.getTimeZone("UTC"));
                time = utc.parse(timeString);
                //        time = new SimpleDateFormat("yyyyMMddhhmmss").parse(timeString);
            } catch (ParseException ex) { /* nothing else to be done */
            }
        }

        return time;
    }
}