Sankalp
Sankalp

Reputation: 173

How to get local date-time and not server date-time

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.

Upvotes: 4

Views: 2806

Answers (6)

ReNiSh AR
ReNiSh AR

Reputation: 2852

Try:

<script>
    var d = new Date();
    alert(d);
</script>

Upvotes: 0

Yogendra Joshi
Yogendra Joshi

Reputation: 228

Use following JQuery ajax call function.

    $.ajax({
        type: "POST",
        url: "ServletTest",
        data: "clientdate=" + new Date()
    });

Upvotes: 0

Deepak Singhal
Deepak Singhal

Reputation: 10866

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().

Upvotes: 1

Chris
Chris

Reputation: 7855

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.

Upvotes: 2

mrab
mrab

Reputation: 2728

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

Upvotes: 1

rai.skumar
rai.skumar

Reputation: 10667

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

Upvotes: 4

Related Questions