/** * 获取当前日期的指定格式的字符串 * * @param format 指定的日期时间格式,若为null或""则使用指定的格式"yyyy-MM-dd HH:mm:ss.SSS" * @return */ public static string getCurrentTimeString(string format) { if (string.IsNullOrWhiteSpace(format)) { sdf.ApplyPattern(FORMAT_DATE_TIME); } else { sdf.ApplyPattern(format); } return(sdf.Format(new Date())); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); SimpleDateFormat sdf = new SimpleDateFormat(); sdf.ApplyPattern("yyyy-MM-dd HH:mm:ss a"); Date date = new Date(); Crashes.GetErrorAttachments = (ErrorReport report) => { return(new ErrorAttachmentLog[] { ErrorAttachmentLog.AttachmentWithText("Crash happened: Hello world! \r\n at " + sdf.Format(date), "hello.txt"), //ErrorAttachmentLog.AttachmentWithBinary(data,"a.png","image/png") }); }; AppCenter.Start("474cb7fe-4c47-4dc2-b4f8-854f0eebe0d9", typeof(Analytics), typeof(Crashes)); AppCenter.LogLevel = LogLevel.Verbose; Analytics.TrackEvent("Loading Main activity... , at " + sdf.Format(date)); Button translateButton = FindViewById <Button>(Resource.Id.TranslateButton); translateButton.Click += (sender, e) => { // Translate user's alphanumeric phone number to numeric //string translatedNumber = Core.PhonewordTranslator.ToNumber(phoneNumberText.Text); //if (string.IsNullOrWhiteSpace(translatedNumber)) //{ // translatedPhoneWord.Text = string.Empty; //} //else //{ // translatedPhoneWord.Text = translatedNumber; //} var result = FromRainbow(Rainbow.Indigo); //Person p = new Person("Abraham", "Qian"); Analytics.TrackEvent($"Now is: {sdf.Format(date)}. Result is: {result.C}"); //Crashes.GenerateTestCrash(); translateButton.Text = $"{result.C}"; }; }
public void TestJapaneseYear3282() { IBM.ICU.Util.Calendar c = IBM.ICU.Util.Calendar.GetInstance(IBM.ICU.Util.ULocale.ENGLISH); c.Set(2003, IBM.ICU.Util.Calendar.SEPTEMBER, 25); IBM.ICU.Util.JapaneseCalendar jcal = new IBM.ICU.Util.JapaneseCalendar(); // jcal.setTime(new Date(1187906308151L)); alternate value jcal.SetTime(c.GetTime()); Logln("Now is: " + jcal.GetTime()); c.SetTime(jcal.GetTime()); int nowYear = c.Get(IBM.ICU.Util.Calendar.YEAR); Logln("Now year: " + nowYear); SimpleDateFormat jdf = (SimpleDateFormat)IBM.ICU.Text.DateFormat .GetDateInstance(jcal, IBM.ICU.Text.DateFormat.DEFAULT, ILOG.J2CsMapping.Util.Locale.GetDefault()); jdf.ApplyPattern("G yy/MM/dd"); String text = jdf.Format(jcal.GetTime()); Logln("Now is: " + text + " (in Japan)"); try { DateTime date = jdf.Parse(text); Logln("But is this not the date?: " + date); c.SetTime(date); int thenYear = c.Get(IBM.ICU.Util.Calendar.YEAR); Logln("Then year: " + thenYear); if (thenYear != nowYear) { Errln("Nowyear " + nowYear + " is not thenyear " + thenYear); } else { Logln("Nowyear " + nowYear + " == thenyear " + thenYear); } } catch (ILOG.J2CsMapping.Util.ParseException ex) { Console.Error.WriteLine(ex.StackTrace); } }
public void Test5345parse() { // Test parse with incomplete information DateFormat fmt2 = IBM.ICU.Text.DateFormat.GetDateInstance(); // DateFormat.LONG, // Locale.US); IBM.ICU.Util.JapaneseCalendar c = new IBM.ICU.Util.JapaneseCalendar(IBM.ICU.Util.TimeZone.GetDefault(), new ULocale("en_US")); SimpleDateFormat fmt = (SimpleDateFormat)c.GetDateTimeFormat(1, 1, new ULocale("en_US@calendar=japanese")); fmt.ApplyPattern("G y"); Logln("fmt's locale = " + fmt.GetLocale(IBM.ICU.Util.ULocale.ACTUAL_LOCALE)); // SimpleDateFormat fmt = new SimpleDateFormat("G y", new // Locale("en_US@calendar=japanese")); long aDateLong = -3197120400000L + 3600000L; // compensate for DST DateTime aDate = ILOG.J2CsMapping.Util.DateUtil.DateFromJavaMillis(aDateLong); // 08 Sept 1868 Logln("aDate: " + aDate.ToString() + ", from " + aDateLong); String str; str = fmt2.Format(aDate); Logln("Test Date: " + str); str = fmt.Format(aDate); Logln("as Japanese Calendar: " + str); String expected = "Meiji 1"; if (!str.Equals(expected)) { Errln("FAIL: Expected " + expected + " but got " + str); } DateTime otherDate; try { otherDate = fmt.Parse(expected); if (!otherDate.Equals(aDate)) { String str3; // ParsePosition pp; DateTime dd = fmt.Parse(expected); str3 = fmt.Format(otherDate); long oLong = ILOG.J2CsMapping.Util.DateUtil.DotNetDateToJavaMillis(otherDate); long aLong = ILOG.J2CsMapping.Util.DateUtil.DotNetDateToJavaMillis(aDate); Errln("FAIL: Parse incorrect of " + expected + ": wanted " + aDate + " (" + aLong + "), but got " + " " + otherDate + " (" + oLong + ") = " + str3 + " not " + dd.ToString()); } else { Logln("Parsed OK: " + expected); } } catch (ILOG.J2CsMapping.Util.ParseException pe) { Errln("FAIL: ParseException: " + pe.ToString()); Console.Error.WriteLine(pe.StackTrace); } }