Java Code Examples for java.util.Date#getHours()

The following examples show how to use java.util.Date#getHours() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Dates.java    From boon with Apache License 2.0 6 votes vote down vote up
public static void fastJsonDateChars( Date date, CharBuf buf ) {

        int day = date.getDate ();
        int month = date.getMonth () +1;
        int year = date.getYear () + 1900;
        int hour = date.getHours ();
        int minute = date.getMinutes ();
        int second = date.getSeconds ();
        int offset = date.getTimezoneOffset ();
        int mili = 1;

        buf.add( '"' );
        buf.add( year ).add( '-' );
        buf.add( Str.zfill( month, 2 ) ).add( '-' );
        buf.add( Str.zfill ( day, 2 ) ).add('T');

        buf.add( Str.zfill( hour, 2 ) ).add( ':' );
        buf.add( Str.zfill( minute, 2 ) ).add( ':' );
        buf.add( Str.zfill( second, 2 ) ).add( "." );
        buf.add( Str.zfill( mili, 3 ) ).add( "Z" );

        buf.add( '"' );

    }
 
Example 2
Source File: ZioEntry.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void setTime(long time) {
    Date d = new Date(time);
    long dtime;
    int year = d.getYear() + 1900;
    if (year < 1980) {
        dtime = (1 << 21) | (1 << 16);
    }
    else {
        dtime = (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
        d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
        d.getSeconds() >> 1;
    }

    modificationDate = (short)(dtime >> 16);
    modificationTime = (short)(dtime & 0xFFFF);
}
 
Example 3
Source File: DateUtils.java    From kafka-monitor with Apache License 2.0 5 votes vote down vote up
/**
 * 取得当前小时数
 *
 * @return
 */
@SuppressWarnings("deprecation")
public static int getNowDayHour()
{
    Date date = new Date();
    int hours = date.getHours();
    return hours;
}
 
Example 4
Source File: ZipUtils.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 5
Source File: ZipUtils.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 6
Source File: ZipEntry.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 7
Source File: ZipUtils.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 8
Source File: DateCell.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void updatePositionFor(DateCellDayItem dayItem, Date targetDay, CalendarItem calendarItem) {

    if (shouldDisplay(calendarItem)) {
        dayItem.getElement().getStyle().clearDisplay();

        Date fromDt = calendarItem.getStartTime();
        int h = fromDt.getHours();
        int m = fromDt.getMinutes();
        long range = calendarItem.getRangeInMinutesForDay(targetDay);

        boolean onDifferentDays = calendarItem.isTimeOnDifferentDays();
        if (onDifferentDays) {
            if (calendarItem.getStart().compareTo(targetDay) != 0) {
                // Current day slot is for the end date and all in-between
                // days. Lets fix also the start & end times.
                h = 0;
                m = 0;
            }
        }

        int startFromMinutes = (h * 60) + m;
        dayItem.updatePosition(startFromMinutes, range);
    } else {
        dayItem.getElement().getStyle().setDisplay(Display.NONE);
    }
}
 
Example 9
Source File: ZipUtils.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 10
Source File: ZipUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 11
Source File: ZipUtils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 12
Source File: Simulator.java    From realtime-analytics with GNU General Public License v2.0 5 votes vote down vote up
private double gethourweight(){
	Date date = new Date();
	int hour = date.getHours();
	int weight = hour/2+1;
	return weight*0.1;
	
}
 
Example 13
Source File: ZipUtils.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
@SuppressWarnings("deprecation") // Use of date methods
private static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return ZipEntry.DOSTIME_BEFORE_1980;
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 14
Source File: ZipUtils.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 15
Source File: ZipUtils.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 16
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkDateSetGetHour() {
    int COUNT = COUNT_FAST;
    Date dt = new Date();
    for (int i = 0; i < AVERAGE; i++) {
        start("Date", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHours(13);
            int val = dt.getHours();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 17
Source File: DateConstants.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
public static CalDate toRPCDateTime(Date date) {
    return new CalDate(date.getYear() + 1900, date.getMonth() + 1, date.getDate(),
            new CalTime(date.getHours(), date.getMinutes(), date.getSeconds()));
}
 
Example 18
Source File: RpcUtils.java    From hasting with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static long getMinute(Date date){
	GregorianCalendar calendar = new GregorianCalendar(1900+date.getYear(),date.getMonth(),date.getDay(),date.getHours(),date.getMinutes());
	return calendar.getTimeInMillis();
}
 
Example 19
Source File: HourMinuteSecond.java    From fenixedu-academic with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Constructs a HourMinuteSecond from a <code>java.util.Date</code> using
 * exactly the same field values avoiding any time zone effects.
 * <p>
 * Each field is queried from the Date and assigned to the HourMinuteSecond. This is useful if you have been using the Date as
 * a local date, ignoing the zone.
 * <p>
 * This factory method always creates a HourMinuteSecond with ISO chronology.
 * 
 * @param date
 *            the Date to extract fields from
 * @return the created HourMinuteSecond
 * @throws IllegalArgumentException
 *             if the calendar is null
 * @throws IllegalArgumentException
 *             if the date is invalid for the ISO chronology
 */
public static HourMinuteSecond fromDateFields(Date date) {
    if (date == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    return new HourMinuteSecond(date.getHours(), date.getMinutes(), date.getSeconds());
}
 
Example 20
Source File: LocalTime.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a LocalTime from a <code>java.util.Date</code>
 * using exactly the same field values.
 * <p>
 * Each field is queried from the Date and assigned to the LocalTime.
 * This is useful if you have been using the Date as a local time,
 * ignoring the zone.
 * <p>
 * One advantage of this method is that this method is unaffected if the
 * version of the time zone data differs between the JDK and Joda-Time.
 * That is because the local field values are transferred, calculated using
 * the JDK time zone data and without using the Joda-Time time zone data.
 * <p>
 * This factory method always creates a LocalTime with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created LocalTime
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the date is invalid for the ISO chronology
 */
@SuppressWarnings("deprecation")
public static LocalTime fromDateFields(Date date) {
    if (date == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    return new LocalTime(
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
        (((int) (date.getTime() % 1000)) + 1000) % 1000
    );
}