There is sometimes the need of a project where you need to create a file i.e. .txt, .csv, .xlsx, etc. We use date time format as required for the project and everything works fine on the local machine but when we deploy on the server it starts showing server date time culture.
Problem Scenario
To create a File with information with date in yyyy-mm-dd format as shown below:
Local Machine-Expected Output:
Figure1: Demonstrating the Requirement.
Server Machine-Output:
Figure2: Demonstrating Server Machine-Output.
Approaches to solve this problem.
• yourDateTime.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
• Creating a method to set the culture.
Calling the method:
After doing these modification the problem got resolved and the output was as shown below on Prod Server:
Figure 3: Demonstrating Server Machine- Correct Output.