Need System time instead of server time JSREPORT.



  • Hi,
    I am using this function for calculating days between startDate and endDate.Further if end date is not available means it takes now date.
    In a hosted server its taking server time as now for endDate.But in my scenario i need my local system time as now.Not a server time. In this any possible to take system time as now in hosted server.

    function CalculateDays(startDate, endDate) {
        if (startDate) {
            let start = new Date(startDate);
            let end = new Date();
            let days, hours, minutes;
            if (endDate) {
                end = new Date(endDate);
            }
            // get total seconds between the times
            let delta = Math.abs(start.getTime() - end.getTime()) / 1000;
    
            // calculate (and subtract) whole days
            days = Math.floor(delta / 86400);
            return days;
        }
    }


  • Your helper function runs in nodejs. This means you can use tricks and libraries that work in node. I believe this information gives you a better idea of how to search for problems solutions.

    You can, for example, use popular package momentjs, that provide helpers to get a date in a specific timezone.

    Install moment-timezone

    npm i moment-timezone --save
    

    Use it in the helper

    const moment = require('moment-timezone')
    function now() {
        return moment.tz("Europe/London").format()
    }
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.