/*
 * @(#)Common15.java
 *
 * Summary: Common methods for JDK 1.5+.
 *
 * Copyright: (c) 2005-2010 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.5+
 *
 * Created with: IntelliJ IDEA IDE.
 *
 * Version History:
 *  1.2 2008-09-09 - initial public release
 *  1.3 2009-04-16 - add StringTools, augments com.mindprod.common11.StringTools
 *  1.4 2009-04-30 - correct bug in StringTools.countLeading(String, String) and hence in trimLeading(String, String)
 *                   add StringTools.pruneExcessBlankLines
 *  1.5 2009-05-03 - add Localise class
 */
package com.mindprod.common15;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * Common methods for JDK 1.5+.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.5 2009-05-03 - add Localise class
 * @since 2005
 */
public final class Common15
    {
    // ------------------------------ CONSTANTS ------------------------------

    /**
     * used to format in Zulu time
     */
    private static final SimpleDateFormat ZULUSDF = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
    // -------------------------- PUBLIC STATIC METHODS --------------------------

    /**
     * convert to Zulu time format
     *
     * @param timestamp milliseconds since 1970-01-01 00:00
     *
     * @return string formatted as 2008-06-22T14:51:18.62Z
     */
    public static String toZulu( long timestamp )
        {
        // Zulu is UTC 24-hour time, no DST.
        final TimeZone utc = TimeZone.getTimeZone( "UTC" );
        ZULUSDF.setTimeZone( utc );
        final String milliformat = ZULUSDF.format( new Date( timestamp ) );
        // convert from milliseconds to centiseconds
        // by chopping off last digit
        return milliformat.substring( 0, 22 ) + 'Z';
        }

    // --------------------------- main() method ---------------------------

    /**
     * TEST harness
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        }
    }
