Java XML Data Type Converter millis2String(long millis)

Here you can find the source of millis2String(long millis)

Description

millis String

License

Mozilla Public License

Declaration

public static String millis2String(long millis) 

Method Source Code


//package com.java2s;
/* //from   w w  w . j  av  a2 s  .  c  om
 * SMART FP7 - Search engine for MultimediA enviRonment generated contenT
 * Webpage: http://smartfp7.eu
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * The Original Code is Copyright (c) 2012-2013 Athens Information Technology
 * All Rights Reserved
 *
 * Contributor:
 *  Nikolaos Katsarakis nkat@ait.edu.gr
 */

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;

public class Main {
    static Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

    public static String millis2String(long millis) {
        int fixMillis = 0;
        String xmlDateTime;
        /*
         * If the millis is divisible by 1000, printDateTime does not add a decimal printout. This workaround fixes this
         * by adding a millisecond before printing
         */
        if (millis % 1000 == 0)
            fixMillis = 1;
        synchronized (cal) {
            cal.setTimeInMillis(millis + fixMillis);
            xmlDateTime = javax.xml.bind.DatatypeConverter.printDateTime(cal);
        }
        // If fixMillis was set to 1, fix the printout
        if (fixMillis == 1)
            xmlDateTime = xmlDateTime.replace(".001Z", ".000Z");
        return xmlDateTime;
    }
}

Related

  1. getLong(byte[] data)
  2. getText(URL url, String user, String password)
  3. getTextAsJavaByteArrayInitializer( String text, String charsetName, int maxArraySize)
  4. getXMLLong(final long value)
  5. isValidValue(String value, Class type)
  6. mixColumns(byte[] input, boolean inv)
  7. printBytes(byte[] data)
  8. printDecimal(BigDecimal value, BigDecimal min, BigDecimal max, int precision, boolean zeroIncluded)
  9. printIntToInteger(int value)