将日期转换为字符串 - SuiteScript 2.0

TMa*_*ann 3 netsuite suitescript suitescript2.0

目标:在NetSuite SuiteScript 2.0预定脚本中将JS Date对象转换为格式为"11/2/2017"的String表示形式.

我有一个日期对象,我需要用于2个目的.在一个,我将用它进行比较(所以我想要实际的日期对象).另一个是我希望它是自定义记录的名称,即字符串值.

我在计划脚本中的NetSuite SuiteScript 2.0(Javascript)中执行此操作.现在日期的toString()是:"2017-11-02T07:00:00.000Z".我希望最终得到的格式是11/2/2017.

当我在浏览器测试应用程序中测试toLocaleDateString()时,我得到11/2/2017 - 我想要的确切格式.但是,当我在SuiteScript 2.0中起诉同样的东西时,我会得到"2017年11月2日".我知道客户端/服务器之间存在差异,但这令人沮丧.

我尝试了format.parse()函数,因为NetSuite的文档声称这相当于1.0 nlapiDateToString()函数.这没用.

除了写我自己的功能(我很想做),有谁知道如何实现这个目标?

W3B*_*GUY 7

要切换到那种格式,你不会使用format.parse,你可以使用format.format.这是一个将日期对象转换为该字符串格式的简单示例.

require(['N/format'],function(format){
  function formatDate(testDate){
    log.debug('testDate: '+testDate);
    var responseDate=format.format({value:testDate,type:format.Type.DATE});
    log.debug('responseDate: '+responseDate);
  }

  var testDate=new Date();
  formatDate(testDate);
});
Run Code Online (Sandbox Code Playgroud)