001package com.nimbusds.oauth2.sdk.util; 002 003 004import java.util.Date; 005 006 007/** 008 * Date utilities. 009 */ 010public class DateUtils { 011 012 013 /** 014 * Converts the specified date object to a Unix epoch time in seconds. 015 * 016 * @param date The date. Must not be {@code null}. 017 * 018 * @return The Unix epoch time, in seconds. 019 */ 020 public static long toSecondsSinceEpoch(final Date date) { 021 022 return date.getTime() / 1000; 023 } 024 025 026 /** 027 * Converts the specified Unix epoch time in seconds to a date object. 028 * 029 * @param time The Unix epoch time, in seconds. Must not be negative. 030 * 031 * @return The date. 032 */ 033 public static Date fromSecondsSinceEpoch(final long time) { 034 035 return new Date(time * 1000); 036 } 037 038 039 /** 040 * Prevents instantiation. 041 */ 042 private DateUtils() { } 043}