Here you can find the source of serializeSqlTime(Time time)
Parameter | Description |
---|---|
time | time to be converted |
public static String serializeSqlTime(Time time)
//package com.java2s; import java.sql.Time; public class Main { /** Number of milliseconds in a minute. */ private static final int MSPERMINUTE = 60000; /** Number of milliseconds in an hour. */ private static final int MSPERHOUR = MSPERMINUTE * 60; /**/*from w w w. jav a 2 s. co m*/ * Serialize time to standard text. Time values are formatted in W3C XML * Schema standard format as hh:mm:ss, with optional trailing seconds * decimal, as necessary. The standard conversion does not append a time * zone indication. * * @param time time to be converted * @return converted time text */ public static String serializeSqlTime(Time time) { StringBuffer buff = new StringBuffer(12); serializeTime((int) time.getTime(), buff); return buff.toString(); } /** * Serialize time to general time text in buffer. Time values are formatted * in W3C XML Schema standard format as hh:mm:ss, with optional trailing * seconds decimal, as necessary. This form uses a supplied buffer to * support flexible use, including with dateTime combination values. * * @param time time to be converted, as milliseconds in day * @param buff buffer for appending time text */ public static void serializeTime(int time, StringBuffer buff) { // append the hour, minute, and second formatTwoDigits(time / MSPERHOUR, buff); time = time % MSPERHOUR; buff.append(':'); formatTwoDigits(time / MSPERMINUTE, buff); time = time % MSPERMINUTE; buff.append(':'); formatTwoDigits(time / 1000, buff); time = time % 1000; // check if decimals needed on second if (time > 0) { buff.append('.'); buff.append(time / 100); time = time % 100; if (time > 0) { buff.append(time / 10); time = time % 10; if (time > 0) { buff.append(time); } } } } /** * Format a positive number as two digits. This uses an optional leading * zero digit for values less than ten. * * @param value number to be formatted (<code>0</code> to <code>99</code>) * @param buff text formatting buffer */ protected static void formatTwoDigits(int value, StringBuffer buff) { if (value < 10) { buff.append('0'); } buff.append(value); } }