/* Showtime.kt Copyright (c) Kari Laitinen http://www.naturalprogramming.com 2020-10-31 File created. If you want to insert a dollar sign into a Kotlin string, you need to write it like "${'$'}" In the GregorianCalendar class, days of week are indicated by numbers from 1 to 7 so that 1 means Sunday and 7 means Saturday. */ import java.util.Calendar import java.util.GregorianCalendar fun main() { val names_of_days_of_week = arrayOf( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ) val names_of_months = arrayOf( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ) val date_and_time_now : Calendar = GregorianCalendar() print( String.format( "\n Current time is: %d:%02d:%02d.%03d \n", date_and_time_now.get( Calendar.HOUR_OF_DAY ), date_and_time_now.get( Calendar.MINUTE ), date_and_time_now.get( Calendar.SECOND ), date_and_time_now.get( Calendar.MILLISECOND ) ) ) print( "\n Current date is: " + names_of_days_of_week [ date_and_time_now.get( Calendar.DAY_OF_WEEK ) - 1 ] + ", day " + date_and_time_now.get( Calendar.DAY_OF_MONTH ) + " of " + names_of_months[ date_and_time_now.get( Calendar.MONTH ) ] + " in year " + date_and_time_now.get( Calendar.YEAR ) + ".\n" ) print( "\n Time zone is: " + date_and_time_now.getTimeZone().getDisplayName() ) print( "\n Difference from UTC/GMT in hours : " + date_and_time_now.get(Calendar.ZONE_OFFSET)/(60*60*1000) ) print( String.format( "\n\n Short 24-h time: %tR", date_and_time_now ) ) print( String.format( "\n Long 24-h time: %tT", date_and_time_now ) ) print( String.format( "\n Long 12-h time: %tr", date_and_time_now ) ) print( String.format( "\n MM/DD/YY date: %tD", date_and_time_now ) ) print( String.format( "\n ISO date: %tF", date_and_time_now ) ) print( String.format( "\n Date and time: %tc", date_and_time_now ) ) print( String.format( "\n Textual date: %1${'$'}tA, %1${'$'}tB %1${'$'}td, %1${'$'}tY \n\n", date_and_time_now ) ) /** // The last statements above could be written alternatively as // shown below. The method System.currentTimeMillis() returns a long // value that contains the current time of the computer in milliseconds // since 1970-01-01 00:00. val current_time_ticks = System.currentTimeMillis() print( String.format( "\n\n Short 24-h time: %tR", current_time_ticks ) ) print( String.format( "\n Long 24-h time: %tT", current_time_ticks ) ) print( String.format( "\n Long 12-h time: %tr", current_time_ticks ) ) print( String.format( "\n MM/DD/YY date: %tD", current_time_ticks ) ) print( String.format( "\n ISO date: %tF", current_time_ticks ) ) print( String.format( "\n Date and time: %tc", current_time_ticks ) ) print( String.format( "\n Textual date: %1${'$'}tA, %1${'$'}tB %1${'$'}td, %1${'$'}tY \n", current_time_ticks ) ) **/ }