简体   繁体   English

来自 C# 的 Highcharts 范围选择器日期格式

[英]Highcharts range selector date formats from C#

I have a C# util function that returns the DateTimeFormat for different regions.我有一个 C# util 函数,它返回不同区域的 DateTimeFormat。 How can I use this to set the range selector date formats for High charts for inputDateFormat and inputEditDateFormat.如何使用它为 inputDateFormat 和 inputEditDateFormat 设置高图表的范围选择器日期格式。 Is there an easy way to convert between these formats?有没有一种简单的方法可以在这些格式之间进行转换?

My C# dateformats looks like this : MM-dd-yyyy我的 C# 日期格式如下所示:MM-dd-yyyy

which I need to map to the high chart format %m-%d-%Y我需要映射到高图表格式 %m-%d-%Y

Well, you aren't clear about what you want.嗯,你不清楚你想要什么。 But I guess, you have different C# date formats for different regions.但我想,不同地区有不同的 C# 日期格式。 And you want to map all of them to HighCharts date format.并且您想将它们全部映射到 HighCharts 日期格式。

So the trick to always keep your data as DateTime type in C#, so you can have 1 DateTime value for all different formats.因此,在 C# 中始终将数据保留为 DateTime 类型的技巧,这样您就可以为所有不同的格式使用 1 个 DateTime 值。 Then serialize/deserialize to Date type in JS.然后在JS中序列化/反序列化为Date类型。 This way we decouple the C# format to JS format.通过这种方式,我们将 C# 格式解耦为 JS 格式。 And for HighCharts, when you getting/setting date value, just use JS Date object.对于 HighCharts,当您获取/设置日期值时,只需使用 JS 日期对象。

 let dateDeserilizedFromBackEnd = new Date(2020, 02, 27); let dateAsStringForHighCharts = moment(dateDeserilizedFromBackEnd).format('MM-DD-YYYY'); alert(dateAsStringForHighCharts);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM