Topic: 一个Java问题请教~(输入一个变量 叫 “11th of January 2002”)

  Print this page

1.一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) Copy to clipboard
Posted by: kof821117
Posted on: 2006-03-17 22:35

Date d = new Date( );

说要输入一个变量 叫 “11th of January 2002”

是不是输入String ***啊???÷

不懂啊~~~

2.Re:一个Java问题请教~ [Re: kof821117] Copy to clipboard
Posted by: zcjl
Posted on: 2006-03-18 00:20

不太明白你要问什么

3.Re:一个Java问题请教~ [Re: kof821117] Copy to clipboard
Posted by: piaoling
Posted on: 2006-03-19 06:15

查看j2se1.4document

4.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: kof821117] Copy to clipboard
Posted by: jackyangf
Posted on: 2006-03-20 17:49

??? 哪里要输?

5.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: kof821117] Copy to clipboard
Posted by: JavaandC
Posted on: 2006-03-21 08:52

你到底想问什么问题,可以说清楚一点不

6.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: kof821117] Copy to clipboard
Posted by: kof821117
Posted on: 2006-03-22 22:48

Enter the parameters needed in the constructor call below to create a Date variable whose intitial value is the 11th of January 2002.
Date d = new Date( );

这是原题目....

谢谢

7.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: kof821117] Copy to clipboard
Posted by: zcjl
Posted on: 2006-03-23 00:17

Date d = new Date(102, 0, 11);

不过这个构造方法已经标记为deprecated了

8.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: zcjl] Copy to clipboard
Posted by: kof821117
Posted on: 2006-03-23 07:49

我在网上看了一些关于这个的例子,
Date compareDate1970 = new Date(24L*60L*60L*1000L);

能告诉我是什么意思吗? (24L*60L*60L*1000L);

其实我不是要你们给我答案,,,是想前辈们讲解这个原理,或者有什么书籍我是可以看的,, 我也查过j2se1.4document, 但是理解得很,模糊,,感谢你们得帮助

9.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: kof821117] Copy to clipboard
Posted by: kof821117
Posted on: 2006-03-23 07:49

这是整个程序:
// -----------------------------------------------------------------------------
// DateExample.java
// -----------------------------------------------------------------------------

/*
* =============================================================================
* Copyright Coffee 1998-2005 Jeffrey M. Hunter. All rights reserved.
*
* All source code and material located at the Internet address of
* http://www.idevelopment.info is the copyright of Jeffrey M. Hunter, 2005 and
* is protected under copyright laws of the United States. This source code may
* not be hosted on any other site without my express, prior, written
* permission. Application to host any of the material elsewhere can be made by
* contacting me at jhunter@idevelopment.info.
*
* I have made every effort and taken great care in making sure that the source
* code and other content included on my web site is technically accurate, but I
* disclaim any and all responsibility for any loss, damage or destruction of
* data or any other property which may arise from relying on it. I will in no
* case be liable for any monetary damages arising from such loss, damage or
* destruction.
*
* As with any code, ensure to test this code in a development environment
* before attempting to run it in production.
* =============================================================================
*/

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* -----------------------------------------------------------------------------
* Used to provide an example that exercises most of the functionality of the
* java.util.Date class. A Date object represents a precise moment in time,
* down to the millisecond. Dates are represented as a long that counts the
* number of milliseconds since midnight, January 1, 1970, Greenwich Meantime.
*
* @version 1.0
* @author Jeffrey M. Hunter (jhunter@idevelopment.info)
* @author http://www.idevelopment.info
* -----------------------------------------------------------------------------
*/

public class DateExample {

/**
* Helper utility used to print
* a String to STDOUT.
* @param s String that will be printed to STDOUT.
*/
private static void prt(String s) {
System.out.printlnMoon;
}

private static void prt() {
System.out.println();
}

private static void doDateExample() {

// To create a Date object for the current
// date and time use the noargs Date() constructor like this:

prt("CURRENT DATE/TIME");
prt("=======================================================");
Date now = new Date();
prt(" new Date() : " + now);
prt();

// To create a Date object for a specific time, pass the number of
// milliseconds since midnight, January 1, 1970, Greenwich Meantime
// to the constructor, like this:
//
// Establish a date object set in milliseconds
// relative to 1/1/1970 GMT

prt("DATE OBJECT FOR SPECIFIC TIME");
prt("=======================================================");
Date specificDate1 = new Date(24L*60L*60L*1000L);
Date specificDate2 = new Date(0L);
prt(" new Date(24L*60L*60L*1000L) : " + specificDate1);
prt(" new Date(0L) : " + specificDate2);
prt();

// You can return the number of milliseconds in the Date
// as a long, using the getTime() method. For example,
// to time a block of code, you might do this
prt("USE getTime() TO RETURN MILLISECONDS");
prt("=======================================================");
Date startTime = new Date();
prt(" Start Time : " + startTime);
// ....
// Insert ant "timed code" here...
// ...
System.out.print(" ");
for (int i = 0; i < 10000000; i++) {
if ((i % 1000000) == 0) {
System.out.print(".");
}
// More "timed" code
}
prt();
Date endTime = new Date();
prt(" End Time : " + endTime);
long elapsed_time = endTime.getTime() - startTime.getTime();
prt("That took " + elapsed_time + " milliseconds");
prt();

// You can change a Date by passing the new date as a number of
// milliseconds since midnight, January 1, 1970, GMT, to the setTime()
// method, like this:
prt("USE gsetTime() TO CHANGE A DATE OBJECT");
prt("=======================================================");
Date changeDate = new Date();
prt(" new Date() : " + changeDate);
changeDate.setTime(24L*60L*60L*1000L);
prt(" setTime(24L*60L*60L*1000L) : " + changeDate);
prt();

// The before() method returns true if this Date is before the Date
// argument, false if it's not.
// For example
// if (midnight_jan2_1970.before(new Date())) {
// The after() method returns true if this Date is after the Date
// argument, false if it's not.
// For example
// if (midnight_jan2_1970.after(new Date())) {
// The Date class also has the usual hashCode(),
// equals(), and toString() methods.
prt("COMPARE DATES USING: before(), after(), equals()");
prt("=======================================================");

Date compareDateNow1 = new Date();
Date compareDateNow2 = (Date) compareDateNow1.clone();
Date compareDate1970 = new Date(24L*60L*60L*1000L);

prt(" Compare (Equals):");
prt(" - " + compareDateNow1);
prt(" - " + compareDateNow2);
if (compareDateNow1.equals(compareDateNow2)) {
prt(" - The two dates are equal.");
} else {
prt(" - The two dates are NOT equal.");
}
prt();

prt(" Compare (Equals):");
prt(" - " + compareDateNow1);
prt(" - " + compareDate1970);
if (compareDateNow1.equals(compareDate1970)) {
prt(" - The two dates are equal.");
} else {
prt(" - The two dates are NOT equal.");
}
prt();

prt(" Compare (Before):");
prt(" - " + compareDateNow1);
prt(" - " + compareDate1970);
if (compareDateNow1.before(compareDate1970)) {
prt(" - " + compareDateNow1 + " comes before " + compareDate1970 + ".");
} else {
prt(" - " + compareDateNow1 + " DOES NOT come before " + compareDate1970 + ".");
}
prt();

prt(" Compare (After):");
prt(" - " + compareDateNow1);
prt(" - " + compareDate1970);
if (compareDateNow1.after(compareDate1970)) {
prt(" - " + compareDateNow1 + " comes after " + compareDate1970 + ".");
} else {
prt(" - " + compareDateNow1 + " DOES NOT come after " + compareDate1970 + ".");
}
prt();

prt("RETRIEVE MILLISECONDS");
prt("=======================================================");

// Establish a date object set in milliseconds relative to 1/1/1970 GMT
Date y = new Date(1000L*60*60*24);

// Retrieve the number of milliseconds since 1/1/1970 GMT (31536000000)
long n = y.getTime();
prt(" Number of milliseconds since 1/1/1970 (GMT) : " + n);

// Computes a hashcode for the date object (1471228935)
int i = y.hashCode();
prt(" Hash code for object : " + i);

// Retrieve the string representation of the date (Thu Dec 31 16:00:00 PST 1970)
String s = y.toString();
prt(" String representation of date : " + s);
prt();

prt("PARSE STRING TO DATE");
prt("=================================================================");
Date newDate;
String inputDate = "1994-02-14";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
System.out.print(" " + inputDate + " parses as ");
try {
newDate = formatter.parse(inputDate);
prt(newDate + ".");
} catch (ParseException e) {
prt("Unparseable using " + formatter + ".");
}
prt();

}

public static void main(String[] args) {
prt();
doDateExample();
}

}

10.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: kof821117] Copy to clipboard
Posted by: jackyangf
Posted on: 2006-03-23 10:04

24L*60L*60L*1000L
24小时 60 分 60 秒 1000 毫秒
date()可以传的参数多,看看文档吧
这里传个long型 正好是一天;而默认是从 1970年算起的
你试一下 System.out.println(new java.util.Date(0).toLocaleString)
和 System.out.println(new java.util.Date(24L*60L*60L*1000L ).toLocaleString)
看一下之间的差别就知道了
时间及转化之类的google或者看文档 关于 dateformat 和 Calendar

11.Re:一个Java问题请教~(输入一个变量 叫 “11th of January 2002”) [Re: kof821117] Copy to clipboard
Posted by: kof821117
Posted on: 2006-03-24 02:10

终于会做了,原来只是懂下脑筋就行了,,谢谢你们的帮助,
year - the year minus 1900; must be 0 to 8099. (Note that 8099 is 9999 minus 1900.)
month - 0 to 11
day - 1 to 31


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923