C# Console Özel Tarih Formatlama Örnekleri
C# console ortamında özel tarih formatlama işlemlerine örnekler yapabiliriz. Aşağıdaki tabloda tarih formatlama işlemi için kullanılan karakterler bulunmaktadır. Bu karakterlerin isimleri ve bu karakterlere örnekler verilmiştir. En sonda da bu karakterler kullanılarak yazdırılan formatlı tarih çıktıları gösterilmektedir.
Karakter | İsmi | Örnek | Örnek Çıktısı |
dd | Gün | Console.Write(“{0:dd}”, DateTime.Now); | 01 |
ddd | Gün İsmi | Console.Write(“{0:ddd}”, DateTime.Now); | Cum |
dddd | Tam Gün İsmi | Console.Write(“{0:dddd}”, DateTime.Now); | Cuma |
hh | Saat | Console.Write(“{0:hh}”, DateTime.Now); | 08 |
HH | Saat(24 Saat) | Console.Write(“{0:HH}”, DateTime.Now); | 20 |
mm | Dakika 00-59 | Console.Write(“{0:mm}”, DateTime.Now); | 53 |
MM | Ay 01-12 | Console.Write(“{0:MM}”, DateTime.Now); | 04 |
MMM | Ay İsmi | Console.Write(“{0:MMM}”, DateTime.Now); | Nis |
MMMM | Tam Ay İsmi | Console.Write(“{0:MMMM}”, DateTime.Now); | Nisan |
yy | Yıl, Son İki Karakter |
Console.Write(“{0:yy}”, DateTime.Now); | 05 |
yyyy | Yıl | Console.Write(“{0:yyyy}”, DateTime.Now); | 2020 |
: | Ayırıcı | Console.Write(“{0:hh:mm:ss}”, DateTime.Now); | 08:53:56 |
/ | Ayırıcı | Console.Write(“{0:dd/MM/yyyy}”, DateTime.Now); | 01/04/2020 |
Kodların C# Console programında çalışır durumdaki görünümü
using System; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Örnek { class Program { static void Main(string[] args) { Console.Write("{0:dd}", DateTime.Now); Console.WriteLine(" - gün"); Console.Write("{0:ddd}", DateTime.Now); Console.WriteLine(" - gün ismi"); Console.Write("{0:dddd}", DateTime.Now); Console.WriteLine(" - tam gün ismi"); Console.Write("{0:hh}", DateTime.Now); Console.WriteLine(" - saat"); Console.Write("{0:HH}", DateTime.Now); Console.WriteLine(" - saat (24 saat)"); Console.Write("{0:mm}", DateTime.Now); Console.WriteLine(" - dakika 00-59"); Console.Write("{0:MM}", DateTime.Now); Console.WriteLine(" - ay 01-12"); Console.Write("{0:MMM}", DateTime.Now); Console.WriteLine(" - ay ismi"); Console.Write("{0:MMMM}", DateTime.Now); Console.WriteLine(" - tam ay ismi"); Console.Write("{0:yy}", DateTime.Now); Console.WriteLine(" - yıl, son iki rakam"); Console.Write("{0:yyyy}", DateTime.Now); Console.WriteLine(" - yıl"); Console.Write("{0:hh:mm:ss}", DateTime.Now); Console.WriteLine(" - ayırıcı"); Console.Write("{0:dd/MM/yyyy}", DateTime.Now); Console.Write(" - ayırıcı"); Console.ReadKey(); } } }
Yukarıdaki C# kodlarının çalıştırıldığında oluşan ekran görüntüsü
Bu Yazıya Tepkin Nedir?
+1
1
+1
+1
+1
+1
+1
+1
<< Önceki Yazı
Sonraki Yazı >>
c# console dersleri, c# console kodları, c# console örnekleri, C# console özel tarih formatlama, c# console projeleri, C# console tarih formatlama, C# console tarih formatlı yazdırma, C# console tarih komutları
Bu güzel çalışma için teşekkür ederiz hocam