2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【UiPath】西暦年・和暦年・月日・曜日ぜーんぶ出したい

Last updated at Posted at 2023-06-19

はじめに

西暦和暦いずれかを出す場合はそんなに苦労しなかったんですけど、
どっちも出したいってなったとき地味に難易度高かったので出し方を記録として残します。

結論

まず最初に西暦年月日曜日出してから、JapaneseCalendarに差し替えて和暦部分を置換します。

今回の実装

image.png

変数の中身

image.png

CultureInfoをJPにしているのは、曜日を出したいためです。

各代入の中身

  • 代入_日付1
hiduke_DateTime.ToString("yyyy(和暦年部分)年MM/dd(ddd)",Cinfo)
  • 代入_JapaneseCalender
    • ここは右辺左辺両方掲載しています。
    • ここでJapaneseCalenderを代入しないと、次の代入のggyyが「西暦23」になってしまうためです。
CInfo.DateTimeFormat.Calendar = New System.Globalization.JapaneseCalendar
  • 代入_日付2
hiduke.Replace("和暦年部分",hiduke_DateTime.ToString("ggyy",CInfo))

実行結果

image.png

無事に

  • 西暦
  • 和暦年
  • 月日
  • 曜日

が出力できました。

今回の実装-NGのすがた-

JapaneseCalenderを代入しなかった場合を見てみます。(JapaneseCalender部分コメントアウトしただけ)

image.png

実行結果-NGのすがた-

image.png

こうなります。「令和」も「5年」でもなく、西暦(20)23という値が出力されてしまいました。

参考文献

おわりに

最後のNGのすがたは自分が個人的にはまったところです。
似たような現象ではまってしまった誰かに届けば幸いです。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?