Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
jerry - Common Java Functionality Copyright (c) 2012-2015, Sandeep Gupta 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 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.
 package com.sangupta.jerry.util;
 import java.util.Date;

 public class DateUtils {

One second expressed as millis
 	public static final long ONE_SECOND = 1000l;

Fifteen seconds expressed as millis
 	public static final long FIFTEEN_SECONDS = 15l * ;

One minute expressed as millis
 	public static final long ONE_MINUTE = 60l * ;

Five minutes expressed as millis
 	public static final long FIVE_MINUTES = 5l * ;

Fifteen minutes expressed in millis
 	public static final long FIFTEEN_MINUTES = 15l * ;

One hour expressed as millis
 	public static final long ONE_HOUR = 60l * ;

6 hours expressed as millis
 	public static final long SIX_HOURS = 6l * ;

12 hours expressed as millis
 	public static final long TWELVE_HOURS = 12l * ;

One day (24-hours) expressed as millis
 	public static final long ONE_DAY = 24l * ;

One week (7 days) expressed as millis
 	public static final long ONE_WEEK = 7l * ;

One month (30-days) expressed as millis
 	public static final long ONE_MONTH = 30l * 

One year (365-days) expressed as millis
 	public static final long ONE_YEAR = 365l * ;

Convert the given time (in millis) represented as a java.lang.Long object into the java.util.Date object.

millis the millis to be converted
the java.util.Date object representation, or null if the incoming millis are null
    public static final Date getDate(Long millis) {
        if(millis == null) {
            return null;
        return new Date(millis);

Find the difference between two java.util.Date objects in milliseconds. The method is null-safe. If either of the object is null, the total time of the other object is returned. If both the objects are null, a difference of 0 is returned. The value is always positive.

first the first java.util.Date object
second the second java.util.Date object
the difference in milli-seconds.
    public static final long getDifference(Date firstDate second) {
    	if(first == null && second == null) {
    		return 0l;
    	if(first == null) {
    		return second.getTime();
    	if(second == null) {
    		return first.getTime();
    	long difference = first.getTime() - second.getTime();
    	if(difference < 0) {
    		return 0 - difference;
    	return difference;
New to GrepCode? Check out our FAQ X