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