Java Unix time unixTimeToString(int time)

Here you can find the source of unixTimeToString(int time)

Description

Helper for CAST({timestamp} AS VARCHAR(n)).

License

Apache License

Declaration

public static String unixTimeToString(int time) 

Method Source Code

//package com.java2s;
/*//from   w w  w  .j  a va  2s . c  om
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you 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.
 */

public class Main {
    /** Helper for CAST({timestamp} AS VARCHAR(n)). */
    public static String unixTimeToString(int time) {
        final StringBuilder buf = new StringBuilder(8);
        unixTimeToString(buf, time);
        return buf.toString();
    }

    private static void unixTimeToString(StringBuilder buf, int time) {
        int h = time / 3600000;
        int time2 = time % 3600000;
        int m = time2 / 60000;
        int time3 = time2 % 60000;
        int s = time3 / 1000;
        int ms = time3 % 1000;
        int2(buf, h);
        buf.append(':');
        int2(buf, m);
        buf.append(':');
        int2(buf, s);
    }

    private static void int2(StringBuilder buf, int i) {
        buf.append((char) ('0' + (i / 10) % 10));
        buf.append((char) ('0' + i % 10));
    }
}

Related

  1. unixTime()
  2. unixtime()
  3. unixTimestamp(int year, int month, int day, int hour, int minute, int second)
  4. unixTimestampToString(long timestamp)
  5. unixtimeToDate(long time)
  6. unixTimeToString(int time, int precision)
  7. unixToGST(double unix)
  8. UnixToJulianDays(double unix)