Adding Unix Time stamp

Les Girvan asked on April 12, 2021 15:25

Hi Guys,

I am looking how to add a unix time to a JavaScript we use in cart tracking. I am using the following method:

{% ECommerceContext.CurrentShoppingCart.ID.ToString() + "_" + Unix Time.ToString()#%}

But all that is retuned is the current OrderID, can anyone advise on how I can add the unix time please?

Recent Answers


Les Girvan answered on April 12, 2021 15:27

Sorry should have said, this is a portal setup v11.0.49 Ultimate

0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on April 12, 2021 16:44

Hi Les Girvan,

I don't think you can get it with the default macro methods, so the easiest solution would be to just create your own custom macro method that will return DateTimeOffset.UtcNow.ToUnixTimeSeconds().

0 votesVote for this answer Mark as a Correct answer

Les Girvan answered on April 12, 2021 17:30

Can I confirm if this is correct format for the custom macro?

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.MacroEngine;
using CMS.Helpers;


/// <summary>
/// Unix time method
/// </summary>
public static class unixtimestamp
{
    public static string unixtime(DateTimeOffset)
    {
        DateTimeOffset.UtcNow.ToUnixTimeSeconds();

    }
}

I am not a coder, but seems like custom macros are required a lot, so trying to understand the logic now.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.