Coldfusion将UNIX转换为人类可读的时间,而不转换时区之间的时间

Coldfusion将UNIX转换为人类可读的时间,而不转换时区之间的时间,coldfusion,timestamp,epoch,Coldfusion,Timestamp,Epoch,我需要从UNIX转换为人类可读的时间,但我不希望像以下代码那样转换时区之间的时间: <cffunction name="EpochToDate" hint="Returns Epoch from Date"> <cfargument name="dateSeconds" default=""> <cfscript> // set the base time from when epoch time starts

我需要从UNIX转换为人类可读的时间,但我不希望像以下代码那样转换时区之间的时间:

<cffunction name="EpochToDate" hint="Returns Epoch from Date">
    <cfargument name="dateSeconds" default="">
    <cfscript>
        // set the base time from when epoch time starts
        startDate = createdatetime( '1970','01','01','00','00','00' );
        if ( NOT isnumeric( arguments.dateSeconds ) )
            return '';

        // return the date
        // this adds the seconds to the startDate and the converts it to to a local time from UTC format
        return dateConvert( "utc2Local", dateadd( 's', arguments.dateSeconds, startDate ) );
    </cfscript>
</cffunction>

//从历元时间开始设置基准时间
startDate=createdatetime('1970','01','01','00','00','00');
if(不是数字(arguments.dateSeconds))
返回“”;
//返回日期
//这会将秒添加到startDate,并将其从UTC格式转换为本地时间
返回dateConvert(“utc2Local”,dateadd('s',arguments.dateSeconds,startDate));

例如,时间戳1532118000应该返回GMT:Friday,2018年7月20日8:20:00 PM,而不是服务器的时区日期。

我认为您需要的方法是首先将历元时间从UTC转换为本地时间,然后对其进行操作。完成后,您可以将其转换回UTC时间。我在两台服务器上进行了尝试,一台位于UTC的前向时区,另一台位于UTC的后向时区

<cffunction name="EpochToDate" hint="Returns Epoch from Date" output="true">
    <cfargument name="dateSeconds" default="">
    <cfscript>
        // set the base time from when epoch time starts
        startDate = DateConvert("utc2Local", CreateDateTime( 1970,1,1,0,0,0 ));
        writedump(startDate);
        if ( NOT isnumeric( arguments.dateSeconds ) )
            return '';

        // return the date
        // this adds the seconds to the startDate and the converts it to to a local time from UTC format
        return DateConvert("local2Utc", dateadd( 's', arguments.dateSeconds, startDate ));
    </cfscript>
</cffunction>
<cfdump var="#EpochToDate(1532118000)#">

//从历元时间开始设置基准时间
startDate=DateConvert(“utc2Local”,CreateDateTime(1970,1,1,0,0));
写入日期(起始日期);
if(不是数字(arguments.dateSeconds))
返回“”;
//返回日期
//这会将秒添加到startDate,并将其从UTC格式转换为本地时间
返回DateConvert(“local2Utc”,dateadd('s',arguments.dateSeconds,startDate));

UTC+5:30
{ts'1970-01-01 05:30:00'}{ts'2018-07-20:20:00'}


UTC-7:00
{ts'1969-12-31 17:00:00'}{ts'2018-07-20:20:00'}

如果不执行
dateConvert()
,返回时会发生什么情况?它返回我的服务器时区中的转换示例:1532114100 return dateConvert(“utc2Local”,dateadd('s',arguments.dateSeconds,startDate))={ts'2018-07-20 23:15:00}return dateadd('s',arguments.dateSeconds,startDate)={ts'2018-07-20 20:15:00'}但是如果您在这里查看它:GMT:2018年7月20日星期五晚上7:15:00