Java Nano Second Convert microSecondToStr(int nanos, int meta)

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

Description

micro Second To Str

License

Open Source License

Declaration

private static String microSecondToStr(int nanos, int meta) 

Method Source Code

//package com.java2s;
/**/*from  w w w  . j  a v  a2 s . co 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 {
    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. appendSecondsToDurationString(final StringBuilder sb, final long seconds, final long nanoseconds)
  2. asNanoSeconds(long seconds)
  3. doubleToNanoseconds(double d)
  4. durationInSeconds(long startNano)
  5. humanReadableNanoseconds(long delta)
  6. nano()
  7. nano2milli(double nano)
  8. nanoSeconds(long millis)
  9. nanoSecondsToSeconds(final long nanoSeconds)