Java TimeUnit Usage parseUntilTime(byte[] untilTime)

Here you can find the source of parseUntilTime(byte[] untilTime)

Description

parse Until Time

License

Apache License

Declaration

public static Date parseUntilTime(byte[] untilTime) 

Method Source Code


//package com.java2s;
/*  Copyright 2013 Florian Bornkessel
    /*w w w .j  a va  2  s  .c  o m*/
   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.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.concurrent.TimeUnit;

public class Main {
    public static Date parseUntilTime(byte[] untilTime) {
        if (untilTime.length < 3)
            return null;

        int year = 2000 + (untilTime[1] & 0x3f);
        int month = (((untilTime[0] & 0xE0) >> 4) | ((untilTime[1] & 0xFF) >> 7)) - 1;
        int day = untilTime[0] & 0x1f;
        int timeInMinutes = (untilTime[2] & 0x3f) * 30;
        int hours = (int) TimeUnit.MINUTES.toHours(timeInMinutes);
        int minutes = (int) TimeUnit.MINUTES.toMinutes(timeInMinutes) - (int) TimeUnit.HOURS.toMinutes(hours);

        Calendar calendar = GregorianCalendar.getInstance();
        calendar.set(year, month, day, hours, minutes, 00);
        return calendar.getTime();
    }
}

Related

  1. parseDuration(String text)
  2. parseRelativeTimeInSeconds(String relativeTime)
  3. parseSecondsFromEpoch(Double d)
  4. parseStringDate(String date)
  5. parseTimeMillis(String timeWithOrWithoutUnit)
  6. pause()
  7. prettyMillis(long mil)
  8. printTimeMap(Map timeMap)
  9. printTimeString(long time)