Search code examples
c#uwpwebassemblyuno-platform

How to overcome missing timezone implementation in the Mono WASM runtime


If I try to print DateTime.Now.TimeOfDay in Uno, Wasm, and UWP will print two different times. Wasm in UTC and UWP in current culture. How can I make sure in both cases I get Local time?


Solution

  • I ran into this issue as well. To resolve use javascript. When wasm is detected use Uno.Foundation.WebAssemblyRuntime.InvokeJS.

        var getTime = Uno.Foundation.WebAssemblyRuntime.InvokeJS("javaTime()");
    

    In a javascript file in your wasm WasmScripts folder

    function javaTime() 
    {
        var date = new Date();
        return date.toLocaleTimeString();
    }