0

I would like to code the Javascript line

date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });

in Kotlin. I can not figure out how to set the second parameter for which only an interface type LocaleOptions exists. If I create an (anonymous) object then I have to initialize and use(!) all variables of interface LocaleOptions but I only want to use hour and minute without displaying the other components.

[See my 2nd comment for a possible answer to this question!]

Tina Hildebrandt
  • 1,277
  • 1
  • 11
  • 20
  • Have you tried approaches listed on this SO page?: https://stackoverflow.com/questions/47006254/how-to-get-current-local-date-and-time-in-kotlin – trebleCode Jan 28 '20 at 14:44
  • No. The approach there is not related to the JS type `Date` but to the one inherited from Java. Might be possible to use it to circumvent the usage of `toLocaleTimeString`. But this does not answer my question. – Tina Hildebrandt Jan 28 '20 at 14:56
  • Please put additional information in the question, not in comments. You can also answer your own question and accept it. – RobG Jan 30 '20 at 23:52

1 Answers1

1

The helper function dateLocaleOptions in date.kt can be used for this purpose:

date.toLocaleTimeString( emptyArray(), dateLocaleOptions { hour = "numeric"; minute = "2-digit" })

Tina Hildebrandt
  • 1,277
  • 1
  • 11
  • 20