Skip to content

Commit aff438d

Browse files
committed
project #7: convert date into minutes
1 parent 9fcb4f5 commit aff438d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

AgeInMinutes/app/src/main/java/com/example/ageinminutes/MainActivity.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,25 @@ class MainActivity : AppCompatActivity() {
4242
// get the reference of the text view
4343
val showSelectedDate = findViewById<TextView>(R.id.tvSelectedDate)
4444
// get the values form selected date
45-
showSelectedDate.setText(selectedDate)
45+
showSelectedDate.text = selectedDate
4646
// converting the date into a standard format
4747
val formatDate = SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH)
4848
// storing the format date
4949
val theDate = formatDate.parse(selectedDate)
50+
// converting the date into minutes
51+
val selectedDateInMinutes = theDate!!.time / 6000
52+
53+
// format the date into minuest
54+
val currentDate = formatDate.parse(formatDate.format(System.currentTimeMillis()))
55+
56+
// calculate the date in minutes
57+
val currentDateToMinutes = currentDate!!.time / 6000
58+
// difference in minutes
59+
val differenceInMinutes = currentDateToMinutes - selectedDateInMinutes
60+
// get the reference of the text view
61+
val showInMinutes = findViewById<TextView>(R.id.tvSelectedDateInMinutes)
62+
showInMinutes.text = differenceInMinutes.toString()
63+
5064
},
5165
year,
5266
month,

AgeInMinutes/app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
android:layout_width="wrap_content"
7171
android:layout_height="wrap_content"
7272
android:layout_marginTop="20dp"
73-
android:textColor="@color/teal_200"
73+
android:textColor="@color/purple_700"
7474
android:textSize="35sp"
7575
android:textStyle="normal" />
7676

0 commit comments

Comments
 (0)