Java BigInteger Calculate getDateOf(BigInteger fileTime)

Here you can find the source of getDateOf(BigInteger fileTime)

Description

Since date values in asf files are given in 100 ns steps since first january of 1601 a little conversion must be done.

License

Open Source License

Parameter

Parameter Description
fileTime Time in 100ns since 1 jan 1601

Return

Calendar holding the date representation.

Declaration

public static GregorianCalendar getDateOf(BigInteger fileTime) 

Method Source Code

//package com.java2s;
/*/*from w  w w.  j  av  a  2 s  . com*/
 * Entagged Audio Tag library
 * Copyright (c) 2004-2005 Christian Laireiter <liree@web.de>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *  
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.math.BigInteger;

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

public class Main {
    /**
     * Since date values in asf files are given in 100 ns steps since first
     * january of 1601 a little conversion must be done. <br>
     * This method converts a date given in described manner to a calendar.
     * 
     * @param fileTime Time in 100ns since 1 jan 1601
     * @return Calendar holding the date representation.
     */
    public static GregorianCalendar getDateOf(BigInteger fileTime) {
        GregorianCalendar result = new GregorianCalendar(1601, 0, 1);
        // lose anything beyond milliseconds, because calendar can't handle
        // less value
        fileTime = fileTime.divide(new BigInteger("10000")); //$NON-NLS-1$
        BigInteger maxInt = new BigInteger(String.valueOf(Integer.MAX_VALUE));
        while (fileTime.compareTo(maxInt) > 0) {
            result.add(Calendar.MILLISECOND, Integer.MAX_VALUE);
            fileTime = fileTime.subtract(maxInt);
        }
        result.add(Calendar.MILLISECOND, fileTime.intValue());
        return result;
    }
}

Related

  1. getBytes(BigInteger bi, int minLen)
  2. getBytes(BigInteger big, int bitlen)
  3. getBytesWithoutSign(BigInteger arg)
  4. getClearExpPipe(BigInteger M)
  5. getCreateLocalNextHopJobKey(Long vpnId, BigInteger dpnId, String prefix)
  6. getDateOf(final BigInteger fileTime)
  7. getDigitCount(BigInteger number)
  8. getHexString(BigInteger bigInt)
  9. getHistogramBigInt(List data, int breaks)