Get time & date independent to the local time of client pc - time

How to get the Exact time and date of the client area, without depending to the local time & date of client's pc. Even if the time and/or date of that pc is set to a wrong time, I want to show the exact time and date of that timezone at my webpage.
May I calculate it using the server time and timezone of client pc and how? Or any other way to do this?
I want any solution with php, mysql, js or jQuery...
Thank you so much...

If you do it with any server side language like php, it will display server time independent of client's computer. Only client side scripts will display client pc time
like php time()

What you need to do is to guess the clients timezone. You can only make a guess. There are services where you can send the clients IP address to have it guess the geographic location, and from that figure out the timezone. But they are not reliable. The best is if you ask the client what timezone he is in.
You can then use the jstimezonedetect JS library to make a guess and let the user confirm that. Once you then know the clients timezone, you need to convert your servers time to the client time. How to do that is answered here.

Related

Is it possible to have multiple timezones in bigquery output?

I have an app that is used worldwide and I would like to be able to see the time of day the users are using the app in their timezone, currently I get the time in the default UTC for every user.
I know it is possible to change the default timezone I report in to another, but I haven't been able to find anything for changing it to multiple timezones.
Is this possible? If so any help/ any helpful documents I could follow? I'm using SQL in bigquery.
Many thanks,

get users current time using web.py

This may well be a silly question but I was wondering if its possible to get the current in time of a user who requests a page from a web.py application in the web.py application. I understand the difference between client side and server side scripting and that web.py is a server side framework but I know that some data is sent to the server when a page is requested and I was wondering if the user's time was such a piece of information.
For this specific case having access to the user's time is not a requirement but a nicety to add extra features if/when nits available.
Is this information retrievable? and if so how might i go about accessing it?
There is no way to do this with http headers.
Using IP: Check out this link using the IP to get local time. Look at this answer for some other python geolocation libraries.
Ask: Why not ask the user what their timezone is?
Client side JavaScript: Determine a User's Timezone

How to handle date in web app?

My web server is in east coast.
I sent an email from my web server at 1PM PST time which is 4PM Eastern time.
I am resided in west coast and when I see the page, it shows 4PM which is future time for me.
How can I see 1PM, someone in east coast 4PM and so on?
The date is stored in MongoDB which is UTC. I also convert date before displaying:
#Model.DateSent.ToLocalTime().ToString();
This is how I set the time when mail is sent:
DateTime.UtcNow <-- So I am storing date in UTC already
Thanks
There are two parts to your question. The first is the mechanics of localizing a dateTime in C#. Since I'm not a Windows guy, I'll leave that to either someone else to answer or you to look up in the docs, but I'm willing to bet that ToLocalTime() has a friend that takes a TimeZone or a Locale.
The second part, which is more interesting, and something I've had to deal with a few times in the past is how to know what timezone to use. There's no right answer, but there are a few strategies:
The simplest, and perhaps the best, if there's a concept in your system of a user account
is to simply make the Locale a user preference.
If there's no concept of a user account one's always logged into there are a few ways
to go
you could make it a choice that is saved in the session, but that's a bit annoying
to force them to select every time
a better alternative might to be geocode the inbound IP address and set it from
that. There are geocoding apps, databases and services. Most cost, but I know
MaxMind has a free edition that does ok. That will mostly work. The catch is
users coming via some large private network. I live near Philadelphia. My home
network usually geocodes pretty well, though a few services place me in Delaware,
where my ISP is located. But at work, where the whole company goes out through
a single web proxy, I look like I'm in North Dakota.
more reliable, but perhaps more involved, is to grab the browser's timezone
using getTimezoneOffset() in Javascript and push the answer up to the server.
I suppose the other option might be to convert the time locally in the browser,
where the timezone is freely availiable, but that implies that the data is
coming down via AJax or similar and then being updated via JavaScript. Fine if
you're doing a app that is fundimentally Ajax RIA based, just send the data
in UTC or as a time_t. But kind of silly and annoying for a classic web app
that isn't already processing all the data client side.
My first choice would be a user preference. If that's not an option I'd probaly push the timezone from the client. And if that's too involved, go for IP geolocation.

Incy IdDayTime Connection problem

I created some software which is using some kind of selfmade license files under Delphi 5 Enterprise. The license expires after a certain time to prevent further use. As it is easy to adjust any desired date on a PC I am trying to get a connection to an internet timeserver.
I tried several codes I found in the internet, none worked. My last try was installing the Indy components and using some simple code like the following:
IdDayTime1.Host := .... desired timeserver
IdDayTime1.Connect;
Label1.Caption := IdDayTime1.DayTimeStr;
IdDayTime1.Disconnect;
I always do not get a connection to a timeserver. This happens in different network areas (at work, at home,...), even if all typical internet software (like firefox, IE,...) works very well in all these networks. So I am sure to have a proper internet connection.
What might be the reason for my problems ?
Do I have to define some special details like ports or sth. else ?
Thanks in advance for any help
Which version of Indy did you use? Which time server are you using? There are several different date/time protocols on the internet. TIdDayTime implements the Daytime Protocol (RFC 867), which is meant for retreiving human-readable date/time strings. For machine-parsable date/time data, especially if you intend to update the PC's clock with it, then use TIdSNTP (Simple Network Time Protocol, RFC 2030) or TIdTime (Time Protocol, RFC 868) instead.

What is a better solution for save client machine time on server?

I need to save client machine time when he log in on my web application. For this I have 2 solution
Using javascript
Store the server time
System.DateTime.Now.ToUniversalTime();
and ask the user in which timezone he is in
TimeZoneInfo indTimeZone = TimeZoneInfo.Local;
return TimeZoneInfo.ConvertTimeFromUtc(date, TimeZoneInfo.Local);
What is the better solution to do this taks, using 1st one or 2nd one?
If there is any better solution then please give me.
To access the client's time, you have to use javascript. All server-based solutions can't access the client's clock.
So, there is no better solution, sorry.

Resources