Tuesday, 22nd June 2010
The new frontier for learning Java

BigDateExperiment.java

From WikiJava

Jump to: navigation, search


This is an experiment I did some time ago, I was curious about the biggest date which is possible to represent in Java using the famous time in milliseconds since the great midnight of the new years eve of 1970 and the most far date in the future representable with a Calendar object. It's been an interesting findings. I hope to see the new millennium bug for the end of the milliseconds in a long.


Contents

the code

Image:250px-Subversion.png
You can download the complete code of this article from the Subversion repository at this link

Using the username:readonly and password: readonly

See the using the SVN repository instructions page for more help about this.
package org.wikijava.time;
 
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Date;
 
/**
 * 
 * prints out the most far date in the future representable with a long in
 * milliseconds
 * 
 * @author Giulio
 */
public class BigDateExperiment {
 
    public BigDateExperiment() {
    }
 
    public static void main(String args[]) {
 
	Date date = new Date(Long.MAX_VALUE);
	System.out.println("the biggest date representable in Java "
		+ "using a java.util.Date: " + date);
 
	Calendar calendar = Calendar.getInstance();
	System.out.println((new StringBuilder(
		"the biggest date representable in Java "
			+ "using java.util.Calendar: ")).append(
		calendar.getMaximum(Calendar.YEAR)).append("-").append(
		calendar.getMaximum(Calendar.MONTH)).append("-").append(
		calendar.getMaximum(Calendar.DAY_OF_MONTH)).toString());
    }
}

Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page


Title (required):

Website:

Comment: