WebSurfer's Home

トップ > Blog 1   |   ログイン
APMLフィルター

日付表示の変更(2)

by WebSurfer 2010年5月21日 00:00

先の投稿 日付表示の変更(1) で、日付の表示について「"yyyy年MM月dd日 HH:mm" としなかったのは、国際化対応にこだわったからです。」などと書いたのですが、結局 "2010年5月1日 12:00" 形式にしました。

今までの形式 "2010/05/01 12:00" では、日本語表示としてはどうしてもイマイチに思えたものですから。(汗)

でも、国際対応にはまだこだわっていて(笑)、ブラウザの言語の設定が日本語(ja-JP または ja)の時のみ "2010年5月1日 12:00" 形式とし、それ以外のときは BlogEngine のデフォルトの "d. MMMM yyyy HH:mm" 形式になるようにしました。

具体的には、PostView.ascx, CommentView.ascx で以下のようにしています(下記は PostView.ascx の場合です)。

<script runat="server"> protected void Page_PreRender(object sender, EventArgs e) { System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture; if (ci.Name == "ja-JP" || ci.Name == "ja") { Label1.Text = Post.DateCreated.ToString("yyyy年M月d日 HH:mm"); } else { Label1.Text = Post.DateCreated.ToString("d. MMMM yyyy HH:mm"); } } </script> <div class="post xfolkentry" id="post<%=Index %>"> <h1> <a href="<%=Post.RelativeLink %>" class="taggedlink"> <%=Server.HtmlEncode(Post.Title) %> </a> </h1> <span class="author"> by <a href="<%=VirtualPathUtility.ToAbsolute("~/") + "author/" + BlogEngine.Core.Utils.RemoveIllegalCharacters(Post.Author) %>.aspx"> <%=Post.AuthorProfile != null ? Post.AuthorProfile.DisplayName : Post.Author %> </a> </span> <asp:Label ID="Label1" runat="server" CssClass="pubDate"></asp:Label> ・・・後略・・・

ブラウザで、言語の設定を変えると表示が変わります。IE8 ですと、[インターネットオプション]→[全般]タブ →[言語(L)]→[言語の優先順位]ダイアログで言語の設定を変えられますので、興味のある方はお試しください。

他に、カレンダーについても日本語の場合の表示を変更しました。その話は別途アップします。

Tags:

BlogEngine.NET

About this blog

2010年5月にこのブログを立ち上げました。主に ASP.NET Web アプリ関係の記事です。

Calendar

<<  2024年3月  >>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar