sebastienros/fluid

Current local date and time not converting to specified timezone

Closed this issue · 2 comments

Fluid.Core Version: 2.4.0
.NET Version: .NET 6
OS: Windows 10 pro

I am trying to convert the date and time from my machine's (local) timezone to the specified timezone. I have tested the same template in the LiuidJs playground and it is working fine.

This is a working template that I have tested in the LiuidJs playground :

{{ "now" | date: "%Y-%m-%dT%H:%M:%S", "Asia/Dubai" }}

I tried this same template in my program using Fluid but it is not converting the date to the specified timezone.

Here is the program :

using Fluid;

namespace LiquidTemplate
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string text = "{{\"now\" | date: \"%Y-%m-%d %H:%M\", \"Asia/Dubai\"}}";
            var parser = new FluidParser();
            var context = new TemplateContext();
            var result = parser.Parse(text).Render(context);
            Console.WriteLine(result);

        }
    }
}

Output :
2023-06-09 12:27 --> local time (Asia/Kolkata)
2023-06-09 12:57 --> expected output should be this (Asia/Dubai)

Note: I have also tried different approaches provided on the official site for the date filter but it is also not working.

@kevit-yuvraj-kanakiya what was the resolution to this?

@mukaofssn You can check the README.md file of this repository, you will find the answer there. you have to pass the timezone filter which is mentioned there. Let me know if it is working for you.