-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdate_service.dart
46 lines (41 loc) · 1.31 KB
/
date_service.dart
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import 'package:intl/intl.dart';
class DateService {
static String dateTimeToWeekDay(DateTime dateTime) {
return days[dateTime.weekday]!;
}
static String dateTimeToString(DateTime dateTime) {
String month = DateService.getMonthStringFromDateTime(dateTime);
String day = DateService.getDayStringFromDateTime(dateTime);
String year = DateService.getYearFromDateTime(dateTime);
String time = DateService.getHourMinutesAMPMStringFromDateTime(dateTime);
return "$month $day, $year at $time";
}
static String getMonthStringFromDateTime(DateTime dateTime) => months[dateTime.month]!;
static String getDayStringFromDateTime(DateTime dateTime) => dateTime.day.toString();
static String getYearFromDateTime(DateTime dateTime) => dateTime.year.toString();
static String getHourMinutesAMPMStringFromDateTime(DateTime dateTime) => DateFormat('hh:mm a').format(dateTime);
static Map<int, String> days = {
0: "Sunday",
1: "Monday",
2: "Tuesday",
3: "Wednesday",
4: "Thursday",
5: "Friday",
6: "Saturday",
7: "Sunday",
};
static Map<int, String> months = {
1: "January",
2: "February",
3: "March",
4: "April",
5: "May",
6: "June",
7: "July",
8: "August",
9: "September",
10: "October",
11: "November",
12: "December"
};
}