如何在XamarinForms中获取设备时间格式

时间:2018-05-02 07:32:09

标签: c# xamarin xamarin.forms xamarin.ios xamarin.android

对于UWP桌面,我们可以使用shorttimepattern https://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.shorttimepattern(v=vs.110).aspx获取桌面时间格式, 比如我们如何在(xamariniOS,android,windows)

中获取设备时间格式

请分享您宝贵的建议。

1 个答案:

答案 0 :(得分:0)

Xamarin.iOS的答案

using System;  

namespace DateTimeFormat
{  
     class Program  
     {  
         static void Main(string[] args)  
         {   
             DateTime aDate = DateTime.Now; 
             Console.WriteLine(aDate.ToString("MM/dd/yyyy"));  
             Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));  
             Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));  
             Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));  
             Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));  
             Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy"));  
             Console.WriteLine(aDate.ToString("dddd, dd MMMM yyyy HH:mm:ss"));  
             Console.WriteLine(aDate.ToString("MM/dd/yyyy HH:mm"));  
             Console.WriteLine(aDate.ToString("MM/dd/yyyy hh:mm tt"));  
             Console.WriteLine(aDate.ToString("MM/dd/yyyy H:mm"));  
             Console.WriteLine(aDate.ToString("MM/dd/yyyy h:mm tt"));  
             Console.WriteLine(aDate.ToString("MM/dd/yyyy HH:mm:ss"));  
             Console.WriteLine(aDate.ToString("MMMM dd"));  
             Console.WriteLine(aDate.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffffffK"));  
             Console.WriteLine(aDate.ToString("ddd, dd MMM yyy HH’:’mm’:’ss ‘GMT’"));  
             Console.WriteLine(aDate.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss"));  
             Console.WriteLine(aDate.ToString("HH:mm"));  
             Console.WriteLine(aDate.ToString("hh:mm tt"));  
             Console.WriteLine(aDate.ToString("H:mm"));  
             Console.WriteLine(aDate.ToString("h:mm tt"));  
             Console.WriteLine(aDate.ToString("HH:mm:ss"));  
             Console.WriteLine(aDate.ToString("yyyy MMMM"));  
             Console.ReadKey();  
        }  
    }  
}  

我已经用这段控制台代码编写了所有的时间和格式。