PHP ini date.timezone? Server or client location time zone? - datetime

I know this might sound a silly question, but I did not find in PHP documentation somewhere were they state loud and clear this one.
I have got a web application.
Users of my web appliations are in Europe, but the server running the web appliation is in US.
How should I set the date.timezone php ini directive???
I suppose to where the server is located so if it's in New York: date.timezone = "America/New_York"
But am I right?

I think that it's better to set server's local timezone or UTC and change user timezone in script using http://pl.php.net/manual/en/function.date-default-timezone-set.php
You can set timezone to Europe/sth or compute it for each client using GeoIP or JavaScript (it should be possible)

According to what I read here around on SO the answers is:
set PHP date.timezone ini directive
to "UTC" (i.e. 0)
let PHP print in pages the date time (UTC) as a simple Unix time stamp (a number)
let Javacscript transform the UTC Unix time stamp in client time by simply doing:
new Date(<?php echo DATE_TIME_SERVER_UTC; ?> * 1000);

http://php.net/manual/en/function.date-default-timezone-set.php and How can I easily convert dates from UTC via PHP?

Related

Why does Firestore timestamp.toDate() add 4 hours to the date in cloud functions, but on the browser, it gets local time correctly?

I can't find any documentation anywhere that explains why on my local client in the browser, when I parse a Timestamp from Firestore, using date.toDate(), on my local client, it shows the date correctly. However, in my Cloud Functions, when I try to parse the same Timestsamp with toDate(), it shows the dates 4 hours ahead.
I've read that you can do something with UTC to remove that offset, but even when I've tried with MomentJS, it doesn't solve the problem.
Firestore Timestamp and JavaScript Date objects don't have specific timestamps encoded in them. If you just console.log() a date value, it will always render that date using the timezone configured on the local machine. What you're seeing is that the server instance provided by Cloud Functions is configured for a different timezone than your local machine.
Momentjs will be able to render it for you in a timezone you choose, but you're probably just not using it correctly.

What's firebase / firestore timezone

Q1. May I know what's the timezone that firebase server and web console is?
Q2. Using FieldValue.serverTimestamp() to save data, how could I convert the timestamp to user timezone?
Q3. Could I configure timezone for firebase server?
Q4. While refer to firebase web console usage info, what's the timezone it showing?
What is the latency for latest usage to appear on web console usage section?
The timezone of Firestore Timestamp is in UTC, if you want to convert that timezone to the timezone your client has do this.
You can set the timezone with DateFormat() and parse the timestamps result with that timezone.
Date date = new Date(timestamp);
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Log.d("Date:",""+utcFormat.format(date));
Regarding Q3, I think since it's from a server-side perspective, you can't change it.
About Q4, I don't really know the latency.
Edit: I have found some info about Q3
https://firebase.google.com/docs/functions/schedule-functions
If you are doing Functions, you can setup the timezone.

Change SQLServer session timeout in web config to use external time source

I have a web server and its session state is stored in a Sql Server. I need to change the timeout to use an external time source. How would I do this?
Ok, it's not hard to do it. I suppose you're able to read that data from the table - related, as you said, to some User Preference - and to put this data in an int:
int myTimeout = [... read from DB];
It's enough to add this line after the login procedure has been completed (or even during the procedure):
Session.Timeout = myTimeout;
Note: the Timeout is in minutes.

Store GMT dates on a US server

I'm from the UK, and have recently deployed a website on WinHost's Basic Package.
When using DateTime.Now() in C#, or GETDATE() in SQL, these are both returning something like GMT-8 (because the server is hosted in the US).
I think I'm a bit limited in terms of permissions on the server (for example I can't change my SQL Login Language).
What is the best method of storing these dates in GMT?
use DateTime.UtcNow and store as it is database.
When reading from database assume UTC and convert into UK time using TimeZoneInfo class.
Note that the SQL should not contain any information about time zone offsets.
In SqlServer use getUtcDate() to store all your datetime values. You can convert it to required timezone in your .NET application.
Description
I think you should store your DateTimes in UTC. Then you can simple convert it to another Timezone with the TimezoneInfo class.
Save DateTime.UtcNow to your database or use getUtcDate inside sql
Let the user choose his timezone and save them to to your database
Convert the UTC Time you have saved to the users timezone using TimeZoneInfo.ConvertTimeFromUtc
Sample
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById(/* destination timezone (users timezone) */);
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(YourDateTimeFromDatabase, cstZone);
More Information
How to do timezones? In asp.net mvc
MSDN - TimeZoneInfo Class

configuring date formats with Windows 7/.NET/SQL Server

I recently copied a web application to a new install of Windows 7 and SQL Server 2008 R2. The application uses LINQ to SQL. Somewhere along the line the parsing of POSTed date strings got screwed up. When the user enters a date string like 4/23/2011, the application rejects it, throwing the error The value '04/23/2011' is not valid for Due. Due (actually DueDate) is a DateTime field in SQL Server.
This used to work fine. I assumed it was an issue with the machine's OS internationalization settings, so I checked and the short and long date formats are set to MM/dd/yyyy and dddd, MMMM dd,yyyy respectively, which looks OK to me. The SQL Server database language is set to English.
The partial class for this property looks like this:
[DisplayName("Due")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime? DueDate { get; set; }
There must be another date format setting I need to tweak. Where should I be looking?
Note: this may be more correctly a serverfault question, but I think devs are much more likely to run into this issue than sysadmins.
More info: SP_CONFIGURE 'default language' returns:
default language 0 9999 0 0
Also: the default language for the database login I am using is English.
I assumed it was an issue with the machine's OS internationalization settings
No, it uses th USERS internationalization settings as told the server by the browser.
the application rejects it, throwing the error The value '04/23/2011' is not valid for Due.
And that is purely bad programming. You should always (!) enter dates either through a parameter or in the ISO form which is totally independant, if you really insist on creating your SQL strings yourself. That woudl be 2011-04-23. SQL Server will accept that format regardless of the locales set somewhere on client or server.

Resources