SP2013得到的时差以分钟为单位

问题描述 投票:0回答:1

我有一个带有日期时间列的列表,称为“状态日期”。我需要做的是在计算列中显示“状态日期”和Now()之间的小时数和分钟数。CONCATENATE方法不起作用,因为它仅在编辑列表项时更新。每当页面加载时,我都需要时间差异来更新。我正在使用变通办法来利用代码中的javascript。但是,当我尝试在新的Date()方法中使用“状态日期”字段时,它返回为“ Wed Dec 31 19:00:43 EST 1969”这是我的计算列的代码。它返回当前小时的分钟数。

<img src='/_layouts/images/blank.gif' onload=""{var startTime=new Date("&[Status Date]&");var endTime=new Date();var difference=endTime.getTime()-startTime.getTime();var rawMins=1000*Math.round(difference/1000);mins= new Date(rawMins);this.parentNode.innerHTML= 'Minutes: '+ mins.getUTCMinutes() ;}"">
javascript sharepoint-2013
1个回答
0
投票

使用JSLink满足此要求。

类似线程here

<script type="text/javascript">
        (function () {
            'use strict';

            var CustomReminder = {};

            /**
             * Initialization
             */
            function init() {

                CustomReminder.Templates = {};

                CustomReminder.Templates.Fields = {
                    'Reminder': {
                        'View': customDTDisplay
                    }
                };

                // Register the custom template
                SPClientTemplates.TemplateManager.RegisterTemplateOverrides(CustomReminder);
            }
            function customDTDisplay(ctx) {                
                //from the context get the current item and it's value
                if (ctx != null && ctx.CurrentItem != null) {
                    //your render logic                    
                }               
            }          

            // Run our intiialization
            init();

        })();
    </script>
© www.soinside.com 2019 - 2024. All rights reserved.