Skip to content

kiwi.time.SimpleDateFormat

Nikos Siatras edited this page Oct 8, 2022 · 5 revisions

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting DateTime to text, parsing text to DateTime, and normalization.

Constructor

constructor(pattern as String)

Constructs a SimpleDateFormat using the given pattern

Parameters:
@param pattern is the pattern describing the date and time format

SimpleDateFormat.formatDateTime()

function formatDateTime(dt as DateTime) as String

Formats a DateTime into a date-time string.

Parameters:
@param dt is the DateTime value to be formatted into a date-time string.

Example:

#include once "kiwi\kiwi.bi"
#include once "kiwi\time.bi" 

' The following timestamp is from Wed Sep 28 2022 06:40:39 UTC +0
Dim timeStampUTC as LongInt = 1664347239101

' Print the utcTime
Dim utcTime as DateTime = DateTime(timeStampUTC, 0) ' UTC +0

' Full date time with AM/PM and UTC TimeZone
Dim sdf as SimpleDateFormat = SimpleDateFormat("dddd dd mmm yyyy h:n:s AM/PM UTC")
print sdf.formatDateTime(utcTime)

' Date-Time (24 Hours Time)
sdf.setPattern("dd/mm/yyyy H:n:s")
print sdf.formatDateTime(utcTime)

' Date only
sdf.setPattern("dd/mm/yyyy")
print sdf.formatDateTime(utcTime)

Output:

Wednesday 28 Sep 2022 6:40:39 AM UTC +0
28/09/2022 6:40:39
28/09/2022