4

I am making a Java web application in whcih customers in different countries are required to upload file through a jsp page.I have to deploy this application in Weblogic server.

Now what i want is their local date-time.I dont want server date-time.

What code should I write in my java application to get their local date and time.

Sankalp
  • 173
  • 2
  • 9
  • 25
  • HTTP POST will not contain that info, I think... Your only option would be to grab the IP of the client socket, do a geoip lookup on it and determine the timezone according to geoip results... – fge Jan 09 '13 at 08:27
  • 1
    Or use JavaScript to read the local time in the browser and then submit it to the server. Or use relative times such as "2 hours ago". – Twilite Jan 09 '13 at 08:28
  • Similar: [*How to detect the timezone of a client?*](https://stackoverflow.com/q/3001260/642706) – Basil Bourque Mar 04 '22 at 05:04

6 Answers6

4

It's tough to get time of user/client unless you pass it explicitly in the post/Ajax call.

Capture time in Javascript and then send it to server in http request.

URL : http://www.w3schools.com/jsref/jsref_obj_date.asp

rai.skumar
  • 10,309
  • 6
  • 39
  • 55
2

You should have a look at this question: Determining a web user's time zone. Please see the answer of "JD Isaacks" with a lot of upvotes.

Than you can pass the timezone "offset" to your Java application through an ajax call and use it to calculate the users local date and time.

Community
  • 1
  • 1
Chris
  • 7,675
  • 8
  • 51
  • 101
1

The only way to get the clients timestamp is to retrieve it on the client and send it to the server.

mrab
  • 2,702
  • 1
  • 17
  • 10
1

Using JavaScript() use Date() function and you can send it to server using ajax. You can call this javascript and ajax function right during bodyLoad().

Deepak Singhal
  • 10,568
  • 11
  • 59
  • 98
  • Can you elborate more on that.How do I capture then information send thru ajax on the otherside – Sankalp Jan 23 '13 at 18:59
0

Use following JQuery ajax call function.

    $.ajax({
        type: "POST",
        url: "ServletTest",
        data: "clientdate=" + new Date()
    });
Yogendra Joshi
  • 228
  • 1
  • 8
0

Try:

<script>
    var d = new Date();
    alert(d);
</script>
ReNiSh AR
  • 2,782
  • 2
  • 30
  • 42