Java SQL Time readTime(ByteBuffer buffer)

Here you can find the source of readTime(ByteBuffer buffer)

Description

read Time

License

LGPL

Declaration

public static java.sql.Time readTime(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.nio.ByteBuffer;
import java.sql.Time;

import java.util.Calendar;

public class Main {
    private static final ThreadLocal<Calendar> localCalendar = new ThreadLocal<Calendar>();

    public static java.sql.Time readTime(ByteBuffer buffer) {
        move(6, buffer);/*  w  w  w.j  av  a 2 s.  co  m*/
        int hour = read(buffer);
        int minute = read(buffer);
        int second = read(buffer);
        Calendar cal = getLocalCalendar();
        cal.set(0, 0, 0, hour, minute, second);
        return new Time(cal.getTimeInMillis());
    }

    public static void move(int i, ByteBuffer buffer) {
        buffer.position(buffer.position() + i);
    }

    public static byte read(ByteBuffer buffer) {
        return buffer.get();
    }

    private static final Calendar getLocalCalendar() {
        Calendar cal = localCalendar.get();
        if (cal == null) {
            cal = Calendar.getInstance();
            localCalendar.set(cal);
        }
        return cal;
    }

    public static void position(int i, ByteBuffer buffer) {
        buffer.position(i);
    }
}

Related

  1. minutesToTime(int minutes)
  2. parse(String dateTimeString)
  3. parseAMPMFormat(String datetimeString)
  4. parseCalendar(final TimeZone timezone, final Locale locale, final String dateformat, final String datestring)
  5. parseDate(String datetime, String format)
  6. removeTimefromDate(Date inputDate)
  7. resetDayTime(Time date)
  8. resetNetworkTimeout(Connection rawConnection, Executor executor, int oldTimeout)
  9. roundDatetimeValue(Object value)