Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
By default date time field is displaying UTC time zone, how can it be changed to current time zone in swagger in .Net core.

What I have tried:

I have not done any code changes except using swashbuckle.AspNetcore 4.0.1 nuget package. when trying to test api, in the post request the start date is showing by default UTC time zone but I would like to show central timezone. is there any way can this be done?
Posted
Updated 3-Jan-19 20:09pm
Comments
MadMyche 3-Jan-19 19:00pm    
How are you calling the APIs which are built on Swagger
chaks nag 4-Jan-19 10:58am    
I don't see any issue in swagger response for time display, what ever it get from DB its showing the same but only problem i have is by default startdate is showing UTC datetime in the request, if i make change in startdate its taking.

1 solution

I had a similar problem with the JSON serializer, I could solve it by using:
var myDate = new DateTime(2019, 1, 1, 12, 0, 0, DateTimeKind.Local);
If you don't want the trailing Timezone information, use:
var myDate = new DateTime(2019, 1, 1, 12, 0, 0, DateTimeKind.Unspecified);
Also see: DateTimeKind Enum (System) | Microsoft Docs[^]
 
Share this answer
 
Comments
Maciej Los 4-Jan-19 8:21am    
5ed!
chaks nag 4-Jan-19 11:16am    
I don't see any issue in swagger response for time display, what ever it get from DB its showing the same but only problem i have is by default startdate is showing UTC datetime in the request, if i make change in startdate manually no issue at all. only the issue i see is by default when testing api in swagger showing default UTC

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900