Howdy
I'm seeking an action to convert UTC time to my current timezone PST.
I did ask Chat GPT, the code compiled but it ultimately didnt work.
using UnityEngine;
using HutongGames.PlayMaker;
using System;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Time)]
[Tooltip("Converts UTC time to PST time.")]
public class ConvertUTCToPST : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The UTC time to convert.")]
public FsmFloat utcTime;
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The converted PST time.")]
public FsmFloat pstTime;
public override void Reset()
{
utcTime = null;
pstTime = null;
}
public override void OnEnter()
{
// Get the current UTC time
var utcNow = DateTime.UtcNow;
// Convert UTC time to PST time
var pstTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var pstTimeValue = TimeZoneInfo.ConvertTime(utcNow, pstTimeZone).ToOADate();
// Store the converted PST time
pstTime.Value = (float)pstTimeValue;
Finish();
}
}
}