Why any Time Zone is automatically converting to Local Time Zone when retrieving from Couchbase SDK

I facing an issue when retrieving date and time along with time zone in C# using couchbase SDK. Please find the details below.

This is the couchbase Insert Query which is having different country date and time along with time zone

Upsert Query
VALUES ( “TZ:Dates”, {
“Tokyo” : “2020-06-18T15:26:00+09:00”,
“Beijing” : “2020-06-18T14:26:00+08:00”,
“Moscow” : “2020-06-18T09:26:00+03:00”,
“Paris” : “2020-06-18T08:26:00+02:00”,
“LosAngeles” : “2020-06-17T23:26:00-07:00”

This is couchbase Select Query, where we can check by using console

** Select Query**
select * from DtTest use keys “TZ:Dates”

Couchbase Select Query Result in console and we didn’t see any issue here
“Beijing”: “2020-06-18T14:26:00+08:00”,
“LosAngeles”: “2020-06-17T23:26:00-07:00”,
“Moscow”: “2020-06-18T09:26:00+03:00”,
“Paris”: “2020-06-18T08:26:00+02:00”,
“Tokyo”: “2020-06-18T15:26:00+09:00”

When we are trying to retrieving from Couchbase SDK in C#

** Couchbase SDK code in C#**

Couchbase SDK Result in C# which is converting the timezone to my system local timezone
“Beijing”: “2020-06-18T11:56:00+05:30”,
“LosAngeles”: “2020-06-18T11:56:00+05:30”,
“Moscow”: “2020-06-18T11:56:00+05:30”,
“Paris”: “2020-06-18T11:56:00+05:30”,
“Tokyo”: “2020-06-18T11:56:00+05:30”

Note : Please help me on this to retrieve exact time zones how we are getting from Couchbase Console

This looks like issue with serialization.


It’s a known limitation of .NET and the DateTime type that it doesn’t handle time zones very well. It actually can’t represent anything but UTC or Local time, no other time zones.

My recommendation would be to use the NodaTime library, which has much richer support. https://www.nuget.org/packages/NodaTime/. This can be combined with https://www.nuget.org/packages/NodaTime.Serialization.JsonNet/ to help support serialization to/from JSON using Newtonsoft.Json (the default serializer used by the Couchbase SDK).

Hopefully that helps.


Also, to be fair you can also try using the System.DateTimeOffset type, which is better with time zones than System.DateTime. But still nowhere near as powerful or flexible as NodaTime.


Did you got fix for this?
I am also facing this issue
In couchbase : “eventTime”: “2022-04-14T19:40:00-07:00”,
From .net 3.2 SDK : “eventTime”:“2022-04-14T18:40:00-04:00”
Can someone help

@rajkumarmore I believe the answers above are still applicable. Using either System.DateTimeOffset or NodaTime should give you more flexibility to work with time zones other than local time on your server and UTC.

Thanks @btburnett3 , please check attached images. For same data in couchbase , getting differebt results from .net SDK2.7 and SDK3.2.8


I feel like this is a different issue, could you open a new forum topic for the conversation? This one is already marked as resolved.

Sure @btburnett3 , created new topic Why any Time Zone is automatically converting to Local Time Zone when retrieving from Couchbase SDK using .Net SDK 3.2.8