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

The following examples show how to use java.util.Date#getSeconds() . 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: Time_12_LocalDateTime_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Constructs a LocalDateTime 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 LocalDateTime.
 * This is useful if you have been using the Date as a local date,
 * 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 LocalDateTime with ISO chronology.
 *
 * @param date  the Date to extract fields from, not null
 * @return the created local date-time, not null
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the date is invalid for the ISO chronology
 */
@SuppressWarnings("deprecation")
public static LocalDateTime fromDateFields(Date date) {
    if (date == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    if (date.getTime() < 0) {
        // handle years in era BC
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        return fromCalendarFields(cal);
    }
    return new LocalDateTime(
        date.getYear() + 1900,
        date.getMonth() + 1,
        date.getDate(),
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
        (((int) (date.getTime() % 1000)) + 1000) % 1000
    );
}
 
Example 2
Source File: ZipUtils.java    From openjdk-jdk8u 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 3
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 4
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 5
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 6
Source File: ZipUtils.java    From hottub 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 7
Source File: ZipUtils.java    From openjdk-jdk8u-backup 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 8
Source File: ZipUtils.java    From Java8CN with Apache License 2.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 9
Source File: ZipUtils.java    From jdk1.8-source-analysis with Apache License 2.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 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 11
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 12
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 13
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 14
Source File: ZipUtils.java    From j2objc with Apache License 2.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;
  }
  // Android-changed: backport of JDK-8130914 fix
  return ((year - 1980) << 25 | (d.getMonth() + 1) << 21 |
          d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
          d.getSeconds() >> 1) & 0xffffffffL;
}
 
Example 15
Source File: DosTime.java    From consulo with Apache License 2.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: ZipUtils.java    From dragonwell8_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 17
Source File: Debug.java    From MiniWeChat-Server with MIT License 4 votes vote down vote up
public static String getTime(){
	Date date = new Date();
	return "[" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "]";
}
 
Example 18
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 19
Source File: TimeOfDay.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a TimeOfDay 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 TimeOfDay.
 * This is useful to ensure that the field values are the same in the
 * created TimeOfDay no matter what the time zone is. For example, if
 * the Calendar states that the time is 04:29, then the created TimeOfDay
 * will always have the time 04:29 irrespective of time zone issues.
 * <p>
 * This factory method always creates a TimeOfDay with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created TimeOfDay
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the date is invalid for the ISO chronology
 * @since 1.2
 */
public static TimeOfDay fromDateFields(Date date) {
    if (date == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    return new TimeOfDay(
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
        (((int) (date.getTime() % 1000)) + 1000) % 1000
    );
}
 
Example 20
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());
}