0% found this document useful (0 votes)
3 views

mobile app activity

Uploaded by

Rana Awais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

mobile app activity

Uploaded by

Rana Awais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

University of Management and

Technology
School of Commerce and Accountancy

Course Title: Mobile application

Deadline: 10th Jan 2025 (Thursday)

Name: Awais Javed ID : f2023387049

Section: QC-A

Acctivity

Question: Program in KOTLIN to print timeZones of five


different countries in
HH:MM:SS format and the gap between those 2 countries
entered by the user.

import java.time.ZoneId

import java.time.ZonedDateTime

import java.time.format.DateTimeFormatter

fun main() {

val countries = mapOf(

"USA" to "America/New_York",

"India" to "Asia/Kolkata",
"Japan" to "Asia/Tokyo",

"Germany" to "Europe/Berlin",

"Australia" to "Australia/Sydney"

val formatter = DateTimeFormatter.ofPattern("HH:mm:ss")

println("Time for different countries:")

countries.forEach { (country, zoneId) ->

val currentTime = ZonedDateTime.now(ZoneId.of(zoneId))

println("$country: ${currentTime.format(formatter)}")

println("\nEnter the names of two countries from the list (e.g., USA, India, Japan, Germany,
Australia):")

val country1 = readLine()?.trim() ?: ""

val country2 = readLine()?.trim() ?: ""

if (countries.containsKey(country1) && countries.containsKey(country2)) {

val zone1 = ZoneId.of(countries[country1]!!)

val zone2 = ZoneId.of(countries[country2]!!)

// Adjust time for demonstration

val time1 = ZonedDateTime.now(zone1).withHour(0).withMinute(0).withSecond(0)


val time2 = ZonedDateTime.now(zone2).withHour(12).withMinute(0).withSecond(0)

val duration = java.time.Duration.between(time1, time2)

val hours = duration.toHours()

val minutes = duration.toMinutes() % 60

val seconds = duration.seconds % 60

println("\nTime gap between $country1 and $country2: $hours hours, $minutes minutes, $seconds
seconds")

} else {

println("Invalid country names entered. Please ensure they are from the list.")

output
Time for different countries:

USA: 13:47:22

India: 00:17:22

Japan: 03:47:22

Germany: 19:47:22

Australia: 05:47:22

Enter the names of two countries from the list (e.g., USA, India, Japan, Germany, Australia):

India

Japan
Time gap between India and Japan: 8 hours, 30 minutes, 0 seconds

You might also like