Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i convert firestore timestamp to date into different format en c#

I'm trying to put a timestamp in a dateTimePicker value in c #, I don't know if it's possible, but I'm getting an error. if is possible, I would like to put it in the format ("dd/MM/yyyy").

dateTimeDate.Value = student.date;

but i get this error,

Cannot implicitly pass the type "Google.Cloud.firestore.Timestamp" in "System.DateTime". 

So i try this, but still not working.

dateTimeDate.Value = student.date.ToDateTime();

How can i fix this, and also i would like to know how to convert it to string to put in a textBox.

like image 993
sebas9981 Avatar asked Sep 05 '25 03:09

sebas9981


1 Answers

Firestore returns Google.Cloud.Firestore.Timestamp object If we convert it to string seems like:

Timestamp: 2021-04-03T10:34:48.865466Z

We can convert it to DateTime object:

DateTime result = DateTime.ParseExact(TIMESTAMP.ToString().Replace("Timestamp:", "").Trim(), 
    "yyyy-MM-ddTHH:mm:ss.ffffffK", null);
like image 85
Akash Shah Avatar answered Sep 07 '25 20:09

Akash Shah