將Json日期格式化

2021-08-02 11:48:44 字數 1155 閱讀 9551

最近在做積分系統的專案,在資料顯示的時候遇到了乙個小問題,直接上圖

通過斷點除錯可以發現,後台資料在被json化的時候時間被格式化成了秒的形式,如圖所示:

經過我的不懈努力終於找了乙個解決方法,就是自己寫乙個方法進行時間轉化

function changedateformat(jsondate)

else if (jsondate.indexof(「-「) > 0)

var date = new date(parseint(jsondate, 10));

var month = date.getmonth() + 1 < 10 ? 「0」 + (date.getmonth() + 1) : date.getmonth() + 1;

var currentdate = date.getdate() < 10 ? 「0」 + date.getdate() : date.getdate();

var hours=date.gethours() < 10 ? 「0」 + date.gethours():date.gethours();

var minutes=date.getminutes() < 10 ? 「0」 +date.getminutes():date.getminutes();

var seconds=date.getseconds() <10 ?」0」 + date.getseconds():date.getseconds();

return date.getfullyear()

+ 「年」

+ month

+ 「月」

+ currentdate

+ 「日」

+ 」 」

+ hours

+ 「:」

+ minutes

+」:」

+seconds;}

最後的結果,完美:

格式化日期

格式化日期 輸出形式取決於使用者計算機的文化設定。using system using system.globalization public class mainclass string date for int i 0 i format.length i d 07 11 2004 輸出 d su...

格式化日期

function dateformat datestr,types dim datestring if isdate datestr false then datestring end if select case types case 1 datestring year datestr month...

日期格式化

日期轉化一 為了達到不同的顯示效果有時,我們需要對時間進行轉化,預設格式為 2007 01 03 14 33 34 要轉化為其他格式,要用到datetime.tostring的方法 string,iformatprovider 如下所示 using system using system.globa...