Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default datetime format for .net core 2.0 webapi

Currently in my local. The API is expecting the same formart as in SQL Server database which is yyyy-mm-dd.

However when i am deploying the application into production server. The API is expecting the datetime format as yyyy-dd-mm.

Is there any way to configure my .net core web api to accept yyyy-mm-dd as default format in every enviroment?

like image 921
mokh223 Avatar asked Dec 02 '22 10:12

mokh223


1 Answers

Please show some code. You can try the following in the AddJsonOptions() pipeline in ConfigureServices()

services
        .AddMvc()
        .AddJsonOptions(options =>
                        {
      //Set date configurations
      //options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd"; // month must be capital. otherwise it gives minutes.
                        });
like image 192
Felix Too Avatar answered Dec 06 '22 15:12

Felix Too