Java Time Readable Format toTime2(int value, int nanos, int meta)

Here you can find the source of toTime2(int value, int nanos, int meta)

Description

to Time

License

Open Source License

Declaration

public static String toTime2(int value, int nanos, int meta) 

Method Source Code

//package com.java2s;
/**//  ww  w.ja  v  a2s .c  o m
 * Project: ${puma-server.aid}
 * 
 * File Created at 2012-6-11 $Id$
 * 
 * Copyright 2010 dianping.com. All rights reserved.
 * 
 * This software is the confidential and proprietary information of Dianping
 * Company. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with dianping.com.
 */

public class Main {
    public static String toTime2(int value, int nanos, int meta) {
        final int h = (value >> 12) & 0x3FF;
        final int m = (value >> 6) & 0x3F;
        final int s = (value >> 0) & 0x3F;

        String format = "%02d:%02d:%02d";
        return String.format(format, h, m, s) + microSecondToStr(nanos, meta);
    }

    private static String microSecondToStr(int nanos, int meta) {
        if (meta > 6) {
            throw new IllegalArgumentException("unknow useconds meta : " + meta);
        }
        String microSecond = "";
        if (meta > 0) {
            microSecond = String.valueOf(nanos);
            if (microSecond.length() < meta) {
                int total = meta % 2 == 0 ? meta : meta + 1;
                int len = total - microSecond.length();
                StringBuilder prefixMicroSecond = new StringBuilder(len);
                for (; len > 0; len--) {
                    prefixMicroSecond.append("0");
                }
                microSecond = prefixMicroSecond.toString() + microSecond;
            }
            microSecond = microSecond.substring(0, meta);
            return "." + microSecond;
        }
        return microSecond;

    }
}

Related

  1. toHumanable(long time_millsecod)
  2. toTime(int duration)
  3. toTime(long ms)
  4. toTime(long nanos)
  5. toTime(long time)
  6. toTimeExpression(long ms, int frames)
  7. toTimeFormat(String _srcTime)
  8. toTimeHumanReadable(final long time)
  9. toTimeSpanDescription(long time)