Here you can find the source of toDecimal(Timestamp instant)
public static BigDecimal toDecimal(Timestamp instant)
//package com.java2s; /*//from www . j ava 2s . co m * Copyright 2013 FasterXML.com * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the license for the specific language governing permissions and * limitations under the license. */ import java.math.BigDecimal; import java.sql.Timestamp; import java.time.Duration; import java.time.Instant; public class Main { private static final char[] ZEROES = new char[] { '0', '0', '0', '0', '0', '0', '0', '0', '0' }; public static BigDecimal toDecimal(Duration instant) { return new BigDecimal(toDecimal(instant.getSeconds(), instant.getNano())); } public static BigDecimal toDecimal(Timestamp instant) { long millis = instant.getTime(); long secs = millis / 1000; return new BigDecimal(toDecimal(secs, instant.getNanos())); } public static BigDecimal toDecimal(Instant instant) { return new BigDecimal(toDecimal(instant.getEpochSecond(), instant.getNano())); } public static String toDecimal(long seconds, int nanoseconds) { StringBuilder string = new StringBuilder(Integer.toString(nanoseconds)); if (string.length() < 9) string.insert(0, ZEROES, 0, 9 - string.length()); return seconds + "." + string; } }