Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

send Timestamp to firebase

i try to make all date in the fire base at the same time zone for users from all the world
how i got the same result from this two lines of code , thought i changed the timezone of the date and still the local date give the same timestamp as UTC time zone

        print(Timestamp.fromDate(DateTime.now()).toDate());
        print(Timestamp.fromDate(DateTime.now().toUtc()).toDate());
        print(Timestamp.fromDate(DateTime.now()).toDate());
        print(Timestamp.fromDate(DateTime.now().toUtc()).toDate());

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The DateTime type has a DateTime.utc() constructor you can use to create a UTC time:

print(DateTime.now());
    print(DateTime.now().toUtc());
    print(DateTime.utc(
      DateTime.now().year,
      DateTime.now().month,
      DateTime.now().day,
      DateTime.now().hour,
      DateTime.now().minute,
      DateTime.now().second,
    ).toUtc());

By default, the DateTime.now() constructor is in the user’s local time:

print(DateTime.now().isUtc); // false
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading