how to retreive the ServletRequest time

S

srini.vinod

Hi,

I'm working a servlet and I'm trying to get the date of a
HttpServletRequest. I have tried using the getHeader(),
getDateHeader() and no use... I tried to get the list of header names
and printed it, the output was:

accept

referer

accept-language

accept-encoding

user-agent

host

connection

cookie


I'm not able to find any header related to date or time... Please help
me sort this out... I've been breaking my head for three days now...

Regards,
Vinod
 
A

Arne Vajhøj

I'm working a servlet and I'm trying to get the date of a
HttpServletRequest. I have tried using the getHeader(),
getDateHeader() and no use... I tried to get the list of header names
and printed it, the output was:

accept
referer
accept-language
accept-encoding
user-agent
host
connection
cookie

I'm not able to find any header related to date or time... Please help
me sort this out... I've been breaking my head for three days now...

The browser does not send time.

You will have to just grab the current time at the server.

Arne
 
L

Lew

Arne said:
The browser does not send time.

You will have to just grab the current time at the server.

Even if the browser did send time, you couldn't rely on it. Server time is
the way to go.
 
S

srini.vinod

Even if the browser did send time, you couldn't rely on it.  Server time is
the way to go.

If I use the server time, how will I be able to know the client
machine time zone... What if the client is in a different timezone
from server...
 
A

Arne Vajhøj

Lew said:
Even if the browser did send time, you couldn't rely on it. Server time
is the way to go.

Depends on whether he need server or client time.

Arne
 
A

Arne Vajhøj

If I use the server time, how will I be able to know the client
machine time zone... What if the client is in a different timezone
from server...

You will not.

If you really need to know the time on the client then you will
need to do some JavaScript stuff to explicit submit it to the
server.

Arne
 
D

Daniel Dyer

Depends on whether he need server or client time.

Arne

He can ask the client for the time, but what if the client tells him it's
1973?

He could look up the IP address with one of those services that locates it
geographically and then determine the timezone from that, but that's not
reliable either (e.g. if there is a proxy involved).

An alternative to doing this on the server, though no more reliable, is to
do whatever time-related stuff needs to be done on the client using
JavaScript (if possible).

Dan.
 
S

Stanimir Stamenkov

Sun, 13 Jan 2008 23:10:43 -0000, /Daniel Dyer/:
He can ask the client for the time, but what if the client tells him
it's 1973?

He can ask the client for a time-zone, instead. And he could use a
default of some predefined time-zone for the country (if any) of the
first locale returned from |ServletRequest.getLocales()|.
 
L

Lew

Arne said:
You will not.

If you really need to know the time on the client then you will
need to do some JavaScript stuff to explicit submit it to the
server.

Even then, you cannot be certain that the time on the client is correct, or
even in the correct time zone.

Why do you need the client time zone anyway?

Why not just store all times in UTC?
 
L

Lew

Daniel said:
He can ask the client for the time, but what if the client tells him
it's 1973?

This is not such a far-fetched notion. Maybe not years off, but I've seen
problems answered on Usenet that had to do with machines being set up in a
different time zone from what its owners think they'd set up, much less what
someone with no operational control at all could guarantee.

The bottom line is that you cannot trust the clock of the client, neither its
correctness nor that it is set for the correct timezone.

This is fine if you don't care what the time is at the client, but only what
the client machine asserts. In that case it's a mistake to think of the
information as a timestamp, rather view it as a time-formatted arbitrary value.
 
L

Lew

Stanimir said:
Sun, 13 Jan 2008 23:10:43 -0000, /Daniel Dyer/:


He can ask the client for a time-zone, instead. And he could use a
default of some predefined time-zone for the country (if any) of the
first locale returned from |ServletRequest.getLocales()|.

Which, like all client-provided information, has to be viewed as likely or
possibly correct rather than certainly correct.
 
A

Arne Vajhøj

Lew said:
Even then, you cannot be certain that the time on the client is correct,
or even in the correct time zone.

No. But it should indicate what the client system is set to.
Why do you need the client time zone anyway?

That must be for the original poster to answer.
Why not just store all times in UTC?

Client time would be bad for that purpose.

But I don't think anyone has said anything about storing the
time as a timestamp.

Arne
 
S

srini.vinod

I'm trying to develop a servlet that displays a map and the time
offset of selected timezone with client time zone...
I tried using javascript, assigned the value to a hidden field, when I
tried to access the value from a servlet, it is null...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top