23.11.2017 Views

java_tutorial

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java<br />

String input = args.length == 0 ? "1818-11-11" : args[0];<br />

System.out.print(input + " Parses as ");<br />

Date t;<br />

}<br />

}<br />

try {<br />

t = ft.parse(input);<br />

System.out.println(t);<br />

} catch (ParseException e) {<br />

System.out.println("Unparseable using " + ft);<br />

}<br />

A sample run of the above program would produce the following result:<br />

$ <strong>java</strong> DateDemo<br />

1818-11-11 Parses as Wed Nov 11 00:00:00 GMT 1818<br />

$ <strong>java</strong> DateDemo 2007-12-01<br />

2007-12-01 Parses as Sat Dec 01 00:00:00 GMT 2007<br />

Sleeping for a While<br />

You can sleep for any period of time from one millisecond up to the lifetime of your<br />

computer. For example, the following program would sleep for 10 seconds:<br />

import <strong>java</strong>.util.*;<br />

public class SleepDemo {<br />

public static void main(String args[]) {<br />

try {<br />

System.out.println(new Date( ) + "\n");<br />

Thread.sleep(5*60*10);<br />

System.out.println(new Date( ) + "\n");<br />

210

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!