Java Reference
In-Depth Information
{
URL u =
new URL("http://www.httprecipes.com/1/3/city.php?city=" + city);
String str = downloadPage(u);
SimpleDateFormat sdf = new SimpleDateFormat(
"MMM dd yyyy hh:mm:ss aa");
Date date = sdf.parse(extract(str, "<b>", "</b>", 1));
return date;
}
/**
* Run the example.
*/
public void go()
{
try
{
URL u =
new URL("http://www.httprecipes.com/1/3/cities.php");
String str = downloadPage(u);
int count = 1;
boolean done = false;
while (!done)
{
String line = extract(str, "<li>", "</a>", count);
if (line != null)
{
int cityNum = Integer.parseInt(
extract(line, "=", "\"", 2));
int i = line.indexOf(">");
String cityName = line.substring(i + 1);
Date cityTime = getCityTime(cityNum);
SimpleDateFormat sdf = new SimpleDateFormat(
"hh:mm:ss aa");
String time = sdf.format(cityTime);
System.out.println(count + " " + cityName + "\t"
+ time);
} else
done = true;
count++;
}
} catch (Exception e)
Search WWH ::




Custom Search