Proper way to format date from database using javascript/jquery

前端 未结 3 1016
礼貌的吻别
礼貌的吻别 2021-01-17 06:11

I am calling my database which contains a datetime datatype. The date looks like this:

2005-05-23 16:06:00.000

I would like to display this in a table when a

3条回答
  •  太阳男子
    2021-01-17 06:35

    The other alternative is to return the formatted string from the controller action. You could even leave the timestamp and return a second field as "Formatted Timestamp" or something similar.

    var listFromDb = ...
    return new Json(listFromDb.Select(itemFromDb => new List { new 
         { Date = itemFromDb.Date, FormattedDate = FormatDate(itemFromDb.Date), ...}
    

提交回复
热议问题