Handlebars DateTimeFormat Helper

2.6k Views Asked by At

I want to display a Datetime as MM-yy format with Handlebars and found the Moment-Helpen but its JS not C# in NuGet there is Moment.js which we can install but don´t know how to use it.

The solution should be something like:

<div>{{formatTime dataDate "MM-YY"}}</div>

I think I have to register some helper with Moment but don´t know how. May someone help me?

1

There are 1 best solutions below

0
On BEST ANSWER

For Handlebars.Net my solution is:

            Handlebars.RegisterHelper(DateFormat, (output, context, data) => 
            {
                DateTime.TryParse(data[0].ToString(), out DateTime date);

                var dictionary = data[1] as HandlebarsDotNet.Compiler.HashParameterDictionary;
                var formatString = dictionary["formatString"];

                output.WriteSafeString(date.ToString(formatString.ToString()));
            });