只有累積,沒有奇蹟

2018年8月18日 星期六

[.NET] 行事曆控制項(ASP.NET calendar)加上農曆日期

摘要:行事曆控制項加上農曆日期
在C#中要如何計算農曆日期?
在 System.Globalization namespace底下,裡面有包含各種曆法的類別
包括台灣(TaiwanCalendar)、日本(JapaneseCalendar)、韓國(KoreanCalendar)...等各國曆法
以下簡單的介紹使用的方式,將ASP.NET 行事曆控制項加上農曆日期顯示
-----------------------------------------------我是分隔線------------------------------------------------------------
Calendar.cs
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. }
  4. protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
  5. {
  6. // 建立農曆類別實體
  7. TaiwanLunisolarCalendar myTaiwan = new TaiwanLunisolarCalendar();
  8. // 取得對應到的農曆月&日
  9. int myMonth = myTaiwan.GetMonth(e.Day.Date);
  10. int myDay = myTaiwan.GetDayOfMonth(e.Day.Date);
  11. string myLunisolarDate = string.Format("
  12. {0}/{1}", myMonth, myDay);
  13. string myLunisolarDateToolTip = string.Format("農曆 {0}月{1}日", myMonth, myDay);;
  14. Label myLabel = new Label();
  15. myLabel.Text = myLunisolarDate;
  16. myLabel.ForeColor = System.Drawing.Color.Blue;
  17. myLabel.Font.Size = FontUnit.XSmall;
  18. myLabel.ToolTip = myLunisolarDateToolTip;
  19. e.Cell.Controls.Add(myLabel);
  20. }
最後顯示的畫面
參考
有問題請多多指教,謝謝 :D

Related Posts:

  • [Redis] C# 存取 Redis - 使用 StackExchange.Redis前言  前面幾篇在介紹 Redis 的安裝以及使用 Redis Desktop Manager 工具,現在終於回到主題如何用 C# 存取 Redis 服務,在官方網站推薦的 .NET Redis client(s) 有很多種,討論度最高的為 StackExchange.Redis 其開發者在 StackExchange 公司工作且 Library 廣為 .NET 開發者推薦,這篇文章要介紹&nbs… Read More
  • [Nuget] The term 'nuget.exe' is not recognized as the name of a cmdlet, function, script file, or operable program問題  最接開發完 Libary 專案要上傳到 nuget server 時,要將 package 檔案透過指令 push 噴 error 錯誤訊息 nuget.exe : The term 'nuget.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the … Read More
  • [.NET] 選擇性參數 (Optional parameters) 的另一種選擇 - OptionalAttribute前言  上一篇文章介紹 了具名引數 (named argument) 的用法,其中被呼叫的方法是使用 C# 4.0 的 optionnal argument 達到方法選擇性參數,過去待過的公司 method 遇到選擇性參數時大多使用 optionnal argument 方式來解決,但其實有另外一種方式可以使用 optionAttribute,這篇就簡單介紹針對同樣需求兩者的寫法 使用… Read More
  • [Nuget] 使用 NuGet Package Explorer 製作 Nuget 套件問題  在上一篇介紹了如何架設公司內部 nuger server,架設完畢後會使用 nuget push 指令將開發完 Library 上傳到公司內部 nuget server 上,但每次都要透過手動打指令 push 難道沒有更快的方法了嗎 ? 今天就要來介紹一套好用的工具 Nuget Package Explorer 可以省去打指令的動作,透過 GUI 的介面將開發好的 Library 上傳到共用或是私人架設的 nuget … Read More
  • [Nuget] 架設公司內部 Nuget Server 前言  在開發上常常會遇到某些代碼是跨專案共用的,在 .NET 中會將重複使用的代碼打包成「套件」,其中包含了編譯後的 dll 以及相關的檔案資訊,接著將套件內容上傳到 Nuget Server 上提供開發者下載使用,Nuget server 有分共用與私人主機兩種,共用的 nuget server 上有相當多好用的 libary 供開發者下載,例如常用的 NLog、newtonsoft.json、NUnit...等各種好用的 pack… Read More

0 意見:

張貼留言

Copyright © 2025 m@rcus 學習筆記 | Powered by Blogger

Design by Anders Noren | Blogger Theme by NewBloggerThemes.com