4

asp.netアプリケーションにハイチャートを実装し、以下のようにdateformat属性を使用してツールチップを設定しました。

tooltip: {
             xDateFormat: '%d/%m/%Y %H:%M:%S' 
             //xDateFormat: '<% = _DateFormat %>'                    
          }

ここで、エンド ユーザーのカルチャ設定に従って表示したいと思います。そのために、1 つの関数とプロパティを作成し、以下のようにページ ロードで設定します。

  _dateFormat = "%d/%m/%Y %H:%M:%S";// 
  //_dateFormat = General.GetUserCulture().DateTimeFormat ; how to convert to above format 

上記の場合、カルチャの日時形式をハイチャートの日時形式文字列に変換するにはどうすればよいですか?

アップデート

HighChart の場合、以下はフォーマット パターンのリストです。

  • %a: 'Mon' のような短い平日。
  • %A: 「Monday」のような長い平日。
  • %d: 月の 2 桁の日、01 から 31。
  • %e: 1 から 31 までの日。
  • %b: 'Jan' のような短い月。
  • %B: 'January' のような長い月。
  • %m: 01 から 12 までの 2 桁の月数。
  • %y: 2009 年の 09 のような 2 桁の年。
  • %Y: 2009 などの 4 桁の年。
  • %H: 24 時間形式の 2 桁の時間、00 から 23。
  • %I: 12h 形式の 2 桁の時間、00 から 11。
  • %l (小文字の L): 12 時間形式の時間、1 ~ 11。
  • %M: 00 から 59 までの 2 桁の分。
  • %p: 大文字の AM または PM。
  • %P: 小文字の AM または PM。
  • %S: 00 から 59 までの 2 桁の秒

したがって、置換を行う場合(@Ruchitの回答はこちら)、期待どおりの結果が得られない場合、以下のコードを考慮すると、あるフォーマットでは真であり、別のフォーマットでは間違っているためです。

_dateFormat = format.ShortDatePattern + " " + format.LongTimePattern;
                _dateFormat = _dateFormat.Replace("yyyy", "%Y")
                                         .Replace("yy", "%y")
                                         .Replace("MMMM", "%B")
                                         .Replace("MMM", "%b")
                                         .Replace("MM", "%m")
                                         .Replace("M", "%m")
                                         .Replace("dddd", "%A")
                                         .Replace("ddd", "%a")
                                         .Replace("dd", "%d")
                                         .Replace("HH", "%H")
                                         .Replace("mm", "%M")
                                         .Replace("ss", "%S");

したがって、すべての形式で機能する一般化されたソリューションを見つけたいと思います。誰かが何か役立つものを見つけたら助けてください!

前もって感謝します。

4

1 に答える 1

2

You can use following code to get the string format of the culture of your current thread.

    System.Globalization.DateTimeFormatInfo format =
         System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat;
string strFormat = format.ShortDatePattern + " " + 
         format.ShortTimePattern;

Once you do this you will have datetime format string like M/d/yyyy h:mm tt. Once you get this you can use replace function for string. You can use strFormat.Replace("M","%m").Replace("d","%d") and so on.
You can use this variable with inline code on the design page.

于 2012-06-27T10:43:05.113 に答える