Search
Sponsors
Sponsors

Posts Tagged ‘System.out.println’

Past and future dates

Tuesday, February 24th, 2009

/**
 * @(#)test.java
 * test application
 */
import java.util.Date;
public class test
{
   
    public static void main(String[] args)
    {
 Date now = new Date();
 
    long past = now.getTime();
    long future = now.getTime();
    past -= 300 * 24 * 60 * 60 * 1000;
 future += 300 * 24 * 60 * 60 * 1000;
 Date pastdate = new Date(past);
 Date futuredate = new Date(future);
    System.out.println(”300 days ago was ” + pastdate);
 System.out.println(”300 days from now will be ” + futuredate);
    }

}

On my system

300 days ago was Sun Feb 22 17:51:41 GMT 2009
300 days from now will be Thu Feb 26 05:18:13 GMT 2009

Get JDK version

Tuesday, February 24th, 2009

/**
 * @(#)test.java
 * test application
 */
import java.io.*;

public class test
{
   
    public static void main(String[] args)
    {
  String version = System.getProperty(”java.version”);
        System.out.println(”JDK version installed is “+ version);

    }

}

On my system I had

JDK version installed is 1.6.0_12

Get the user name

Tuesday, February 24th, 2009

/**
 * @(#)test.java
 * test application
 */
import java.io.*;

public class test
{
   
    public static void main(String[] args)
    {
  String name = System.getProperty(”user.name”);
        System.out.println(name);
    }

}

Translate