//Get what uou need from the data
var result = context.Student
.Where(x => x.Name) //Query the Db for what you need
.Select(x => new
{
Birthday = x.Birthday.ToString("MM/dd/yyyy"), //Use format you need
Name = x.Name
//Add props you need from student
}).ToList();
public class Student
{
//All student props
[NotMapped]
public string ModifiedBirthday => this.Birthday.Value.ToString("MM/dd/yyyy"); // Format you need
}
1条答案
按热度按时间jv4diomz1#
试试这样
您可以在这里看到一些日期时间格式https://www.c-sharpcorner.com/blogs/date-and-time-format-in-c-sharp-programming1
或者,如果您想使用该模型,则可以在不影响数据库的情况下向其中添加ModifiedBirdday,如