How do I display todays date in Node.js Jade?

前端 未结 7 1488
囚心锁ツ
囚心锁ツ 2021-01-31 15:04

I am new to Node.js and Jade and I have tried to use #{Date.now()} and it\'s giving me numbers. How do I display the date in mm/dd/yy format?

7条回答
  •  你的背包
    2021-01-31 15:45

    I found a solution 1.Create a function in pug using - syntax 2.pass the varible to the function when pug.js is binding variables to the pug template

        -function prettyDate(dateString){
                            -var date = new Date(dateString);
                            -var d = date.getDate();
                            -var monthNames = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
                            -var m = monthNames[date.getMonth()];
                            -var y = date.getFullYear();
                            -return d+' '+m+' '+y;
                        -}
    3.span.post-date #{prettyDate(val.date)};
    

提交回复
热议问题