0

I am trying to retrieve the date-time in SSJS. I have created the below code on the cloud page, to retrieve the locale date time.

<script runat="server">
    Platform.Load("Core","1");

    var api = new Script.Util.WSProxy();

    try {
        var request = SystemDateToLocalDate(Now());
        Write(Stringify(request));

    } catch(err) {
        Write(Stringify(err));
    }
</script>    

When I run this code in cloudpage, getting the below error:

{"message":"Object expected: SystemDateToLocalDate","jintException":"Jint.Native.JsException: Exception of type 'Jint.Native.JsException' was thrown.\r\n at Jint.ExecutionVisitor.Visit(MethodCall methodCall)\r\n at Jint.Expressions.MethodCall.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(MemberExpression expression)\r\n at Jint.Expressions.MemberExpression.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(VariableDeclarationStatement statement)\r\n at Jint.Expressions.VariableDeclarationStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(BlockStatement statement)\r\n at Jint.Expressions.BlockStatement.Accept(IJintVisitor visitor)\r\n at Jint.ExecutionVisitor.Visit(TryStatement statement)","description":"Jint.Native.JsException: Object expected: SystemDateToLocalDate\r\nException of type 'Jint.Native.JsException' was thrown. - from Jint\r\n\r\n"}

The below code works fine but the output is the systemdate. I want it to be the local time

<script runat="server">
    Platform.Load("Core","1");

    var api = new Script.Util.WSProxy();

    try {
        /*var request = SystemDateToLocalDate(Now());
    
        Write(Stringify(request));*/
        
      var date= Now();

     var d = new Date(date); 

   Write(d);

    } 
    catch(err) {
        Write(Stringify(err));
    }
</script>    

1 Answer 1

1

I got the script working. Below script is generating the output as localdate time. I got the reference from link

<script runat="server">
    Platform.Load("Core","1");

    var api = new Script.Util.WSProxy();

    try {
    // Output the locatltime    
   var localTime = DateTime.SystemDateToLocalDate(Now());
   Write(localTime);
   //output the sytem time
   var systemTime = DateTime.LocalDateToSystemDate(Now());
   Write(systemTime);
    } 
    catch(err) {
        Write(Stringify(err));
    }
</script> 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .