Here you can find the source of timestampToMicros(Timestamp timestamp)
Parameter | Description |
---|---|
timestamp | the timestamp to convert to microseconds |
public static long timestampToMicros(Timestamp timestamp)
//package com.java2s; // Licensed to the Apache Software Foundation (ASF) under one import java.sql.Timestamp; public class Main { /**/*from ww w . jav a2 s.c om*/ * Converts a {@link Timestamp} to microseconds since the Unix epoch (1970-01-01T00:00:00Z). * * Note: Timestamp instances with nanosecond precision are truncated to microseconds. * * @param timestamp the timestamp to convert to microseconds * @return the microseconds since the Unix epoch */ public static long timestampToMicros(Timestamp timestamp) { // Number of whole milliseconds since the Unix epoch, in microseconds. long millis = timestamp.getTime() * 1000L; // Sub millisecond time since the Unix epoch, in microseconds. long micros = (timestamp.getNanos() % 1000000L) / 1000L; if (micros >= 0) { return millis + micros; } else { return millis + 1000000L + micros; } } }