-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeConverter.cs
More file actions
31 lines (26 loc) · 1.08 KB
/
TimeConverter.cs
File metadata and controls
31 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchedulingApp
{
public static class TimeConverter
{
// Converts a UTC DateTime to Eastern and Local Time
public static (string Eastern, string Local) FormatAppointmentTimes(DateTime utcDateTime)
{
TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime easternTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, easternZone);
DateTime localTime = utcDateTime.ToLocalTime();
string easternFormatted = easternTime.ToString("MMM dd, yyyy h:mm tt");
string localFormatted = localTime.ToString("MMM dd, yyyy h:mm tt");
return (easternFormatted, localFormatted);
}
// Converts a local time (entered by the user) to UTC for DB storage
public static DateTime ConvertLocalToUtc(DateTime localDateTime)
{
return localDateTime.ToUniversalTime();
}
}
}