Printing out dates
6 Message(s) by 4 Author(s) originally posted in java language
| From: KenStahl |
Date: Wednesday, April 25, 2007
|
I have written a small
program that looks like this:
import JAVA.lang.*;
import JAVA.util.*;
import JAVA.text.*;
class date test {
public static void main(String args[]){
Date nd = null;
String ds = "01/01/1970 00:00:00
GMT ";
String df = "MM/dd/yyyy HH:mm:ss zzz";
SimpleDateFormat f = new SimpleDateFormat(df);
try {
nd = f.parse(ds);
}
catch (Exception e){
System.out.println(e.toString());
}
System.out.println("Date: " + nd);
}
}
When I
run this program the
output is: Date: Wed Dec 31 19:00:00 EST 1969
I want it to print out the
literal time that I supplied so it'd be: Thr
Jan 1 00:00:00 GMT 1970
I can not set the timezone in the date
object , so what'd I have to do to
make it come out right. I suspect that it'd involved a Calendar object,
but how do I move the time from the f.parse(ds) into a Calendar object that
is set up for GMT?
| From: Dirk Michaelsen |
Date: Thursday, April 26, 2007
|
wrote in message:
I have written a small program that looks like this:
[...]
When I run this program the output is: Date: Wed Dec 31 19:00:00 EST 1969
on my
system the output of your class is:
Date: Thu Jan 01 01:00:00 CET 1970
cu
Dirk
| From: Odin |
Date: Thursday, April 26, 2007
|
The Date class follows the
locale for the system where the program is run.
That's part of the problem. Date should be locale neutral. If you think
about it, the time in milliseconds that is stored internally'd be the
same for both you and I - but when it is just printed out as I did in the
program it is the same as if I had written it as nd.toString(), so somewhere
the assumption is being made that whenever toString() is used, it should
output the value for the
current locale.
What I need is a way to make it print out for the locale/timezone of my
choice.
| From: midleton |
Date: Saturday, April 28, 2007
|
Just try :
import JAVA.text.SimpleDateFormat;
import JAVA.util.Date;
import JAVA.util.TimeZone;class DateTest2 {
public static void main(String args[]){
Date nd = null;
String ds = "01/01/1970 00:00:00 GMT";
String df = "MM/dd/yyyy HH:mm:ss zzz";
SimpleDateFormat f = new SimpleDateFormat(df);
f.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
nd = f.parse(ds);
}
catch (Exception e){
System.out.println(e.toString());
}
System.out.println("Date: " + f.format(nd));
}
}
that should do the trick.
Tom.
| From: KenStahl |
Date: Sunday, April 29, 2007
|
Thanks. I will give that a try.
| From: KenStahl |
Date: Sunday, April 29, 2007
|
I just tried it. That did the trick. Now I know how to solve the rest of my
problems. Thanks for the assist.
Next Message: Question
Blogs related to Printing out dates
Re : Re: Re : Re: Re : Re: Re : Re: Re : Re: Question concerning ...
When you
print out the results of the > parsing,you should see something like field:value1 field:value2, > which are built up > under the covers to be a BooleanQuery with a bunch of clauses. > > I think, though, I'm really at the end of
...
RE: Creating a XML-RPC Client
Java Client. Hello everybody! The example was not working for me, perhaps something got
out of
date as org.apache.xmlrpc evolved. It would be great if someone at Atlassian confirmed this and/or updated the article accordingly.
...
Re: Issue while parsing XML files due to control characters, help ...
The > >>> problems are arranged in the following way:example sentencesconcise > >>> description of the problemkeyword for the type of problemThe sources > >>> (first appearance in
print) of the sentences have been left > >>>
out,because
...
Re: Issue while parsing XML files due to control characters, help ...
With the above idea, I created 70 directories each with the name of > dumpfile like : oai_citeseer_1/ etc and under this I will have 10000 > XML's being extracted
out using some
Java program. > > 3. So now coming to my program,
...
Re : Re: Re : Re: Re : Re: Problem with a search engine
I did try to
print out the query before and after it gets processed > by QueryParser and let say my query is "2003", before and after it > will be "2003". If I put "report 2003" the query will be, before > and after getting into the
...
problem in date plz find out of the mistake on my code only 1 row ...
import
java.io.FileInputStream; import
java.text.SimpleDateFormat; import
java.util.
Date; //import
java.util.Iterator; import.