增加ChartuseUtc参数设置显示时间是否用UTC时间

This commit is contained in:
monitor1394
2025-10-31 08:39:29 +08:00
parent 2cb82526bc
commit f1c9a3ac4b
12 changed files with 42 additions and 33 deletions

View File

@@ -31,6 +31,11 @@ namespace XCharts.Runtime
}
}
/// <summary>
/// Whether to use UTC time for the chart.
/// ||图表的时间是否都显示为UTC时间。
/// </summary>
public bool useUtc { get { return m_UseUtc; } set { m_UseUtc = value; } }
/// <summary>
/// The theme.
/// ||</summary>
public ThemeStyle theme { get { return m_Theme; } set { m_Theme = value; } }

View File

@@ -16,6 +16,7 @@ namespace XCharts.Runtime
public partial class BaseChart : BaseGraph, ISerializationCallbackReceiver
{
[SerializeField] protected string m_ChartName;
[SerializeField] protected bool m_UseUtc = true;
[SerializeField] protected ThemeStyle m_Theme = new ThemeStyle();
[SerializeField] protected Settings m_Settings;
[SerializeField] protected DebugInfo m_DebugInfo = new DebugInfo();

View File

@@ -100,9 +100,9 @@ namespace XCharts.Runtime
return NumberToStr(value, numericFormatter);
}
public static string NumberToDateStr(double timestamp, string formatter)
public static string NumberToDateStr(double timestamp, string formatter, bool local = false)
{
var dt = NumberToDateTime(timestamp);
var dt = NumberToDateTime(timestamp, local);
try
{
return dt.ToString(formatter, ci);
@@ -132,11 +132,11 @@ namespace XCharts.Runtime
}
}
public static DateTime NumberToDateTime(double timestamp)
public static DateTime NumberToDateTime(double timestamp, bool local = false)
{
if (!s_TimestampToDateTimeDict.ContainsKey(timestamp))
{
s_TimestampToDateTimeDict[timestamp] = DateTimeUtil.GetDateTime(timestamp);
s_TimestampToDateTimeDict[timestamp] = DateTimeUtil.GetDateTime(timestamp, local);
}
return s_TimestampToDateTimeDict[timestamp];
}