What's firebase / firestore timezone - firebase

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.

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.

How can i get client system current datetime from sql instance?

Sql server getdate() function fetch server current datetime, how can I get client system current datetime from sql server instance?.
One of our client using one database for multiple companies operating from different time zones, being a huge database with many tables, procedures, functions and the getdate() function is used as default value for many area.
You can't. The SQL Server doesn't know anything about the time where the client that called it is located.
Consider using getutcdate() instead. Use UTC exclusively in your database, then convert between time zones in the application layer.
If you feel you need to convert between time zones in the database itself, you will need a third-party solution, such as my SQL Server Time Zone Support package.
I have same problem. I found this link:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/290a0085-47a5-48ab-9557-1b59ee269a40/call-getdate-from-linked-server?forum=transactsql
declare #rmt_time datetime;
exec('SET ? = CURRENT_TIMESTAMP', #rmt_time OUTPUT) at [remote_server];
select CURRENT_TIMESTAMP as local_time, #rmt_time as rmt_time;
Hope this helps.

Setting project localization date

How can I setup my ASP.net MVC 4 project to use my country datetime, because I am hosting my app on the cloud - apphabour?
I am now using Datetime.Now() to retrieve the latest app?
Datetime.now returns the current time and time zone defined by the settings for the server clock or the domain time service for the ad controller. Normally dates stored in a database ( or code ) are returned as UFC date time so that web clients /windows clients can convert utc time to local time defined by the settings on each workstation.

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

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

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?

Resources