/// <summary> /// Chat Date formatter. /// </summary> public static string GetFormattedDate(long milliSeconds) { string formattedDate = string.Empty; try { DateTime time = START_DATE.AddMilliseconds(milliSeconds * 1000L); TimeZoneInfo localZone = TimeZoneInfo.Local; time = time.AddHours(localZone.BaseUtcOffset.TotalHours); if (time.Date == DateTime.Now.Date) { formattedDate = String.Format("{0:HH:mm}", time); } else if (time.Year == DateTime.Now.Year) { formattedDate = String.Format("{0:dd/MMM} {0:HH:mm}", time, time); } else { formattedDate = String.Format("{0:dd/MM/yy} {0:HH:mm}", time, time); } } catch (Exception ex) { Debug.WriteLine("GetFormattedDate failed:" + ex.Message); } return(formattedDate); }
/// <summary> /// Dialogs Date formatter. /// </summary> public static string GetFormattedDialogTime(long milliSeconds) { DateTime time = START_DATE.AddMilliseconds(milliSeconds * 1000L); TimeZoneInfo localZone = TimeZoneInfo.Local; time = time.AddHours(localZone.BaseUtcOffset.TotalHours); string formattedDate; TimeSpan res = DateTime.Now - time; if (DateTime.Now.Date == time.Date) { formattedDate = String.Format("{0:HH:mm}", time); } else if (DateTime.Now.Day - 1 == time.Day) { formattedDate = AppResources.Yesterday; } else if (time.Year == DateTime.Now.Year) { formattedDate = String.Format("{0:dd/MM}", time, time); } else { formattedDate = String.Format("{0:dd/MM/yy}", time, time); } return(formattedDate); }
/// <summary> /// Chat status Date formatter. /// </summary> public static string GetFormattedStatusTime(long milliSeconds) { string result; DateTime time = START_DATE.AddMilliseconds(milliSeconds * 1000L); TimeZoneInfo localZone = TimeZoneInfo.Local; time = time.AddHours(localZone.BaseUtcOffset.TotalHours); TimeSpan res = DateTime.Now - time; if (res.TotalMinutes < 60) { result = res.TotalMinutes.ToString("0") + AppResources.TotalMinutes; } else if (res.TotalDays < 1) { result = res.TotalHours.ToString("0") + AppResources.TotalHours; } else { result = res.TotalDays.ToString("0") + AppResources.TotalDays; } return(result); }