japanese date format
Currently at work, I’m doing an upgraded version of an in-house system. It was developed using MS Access, and now, they want a VB.NET 2.0 and SQL Server 2005 version.
One of the reports that I’ll use needs the date in Japanese format. [The Japanese date format uses eras. For example, we're in 2008; in japanese calendar, that's 平成20.] It took me some time to figure out how to do that.
So in order to do this, first, import System.Globalization. Then, get the DateTimeFormat of the Japanese Calendar with CultureInfo(“ja-JP”).DateTimeFormat. Don’t forget to set the calendar of the DateTimeFormat into JapaneseCalendar. Lastly, the format pattern of the year is “ggyy“, where gg stands for the kanji of the era, and the yy is for the year.
Here’s a sample source code:
Imports System.Globalization
Module Test
Sub Main()
Dim dtNow As Date = Date.Now
Dim jpnCalFormat As System.Globalization.DateTimeFormatInfo = New CultureInfo("ja-JP").DateTimeFormat
jpnCalFormat.Calendar() = New JapaneseCalendar()
Dim jpnDate As String = dtNow.ToString("ggyy年MM月dd日", jpnCalFormat)
System.Console.WriteLine(jpnDate)
End Sub
End Module
Another way to do this is this:
Dim S As String = Microsoft.VisualBasic.Compatibility.VB6.Format(Date.Now, "ggge年mm月dd日")
Filed under: Programming | Leave a Comment
Tags: date format, jap date, vb 2005
Search
-
You are currently browsing the The Geeky Side of Me weblog archives.
No Responses Yet to “japanese date format”