-
Notifications
You must be signed in to change notification settings - Fork 3
kiwi.time.Calendar
The Calendar object provides methods for converting between a specific instant in time and a set of fields calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. An instant in time can be represented by a millisecond value that is an offset from midnight (00:00:00) January 1, 1970 00:00:00.000 Coordinated Universal Time (UTC)
function getTime() as DateTime
Returns a Date object representing this Calendar's current time value.
function Calendar.getTimeInMillis() as LongInt
Returns this Calendar's current time value in milliseconds.
function Calendar.createTime(timeInUTCMillis as LongInt) as DateTime
Creates and return's a DateTime object according to the given time in milliseconds elapsed since midnight (00:00:00), January 1st, 1970, Coordinated Universal Time (UTC) and the Calendar's TimeZone.
function Calendar.createTime(dYear as Integer, dMonth as Integer, dDay as Integer, dHour as Integer, dMinute as Integer, dSecond as Integer) as DateTime
Creates and return's a DateTime object according to the given year, month, day, hour, minute and seconds
Example:
#include once "kiwi\kiwi.bi"
#include once "kiwi\time.bi"
' Initialize a Calendar using the UTC+2 TimeZone
Dim myCalendar as Calendar = Calendar(+2)
' Create a new DateTime
Dim dt as DateTime = myCalendar.createTime(1940, 10, 28, 05, 15, 00)
print dt.toString()
Output:
Mon Oct 28 1940 05:15:00 UTC +2
The following simple examples will try to explain the use of Kiwi's Calendar object.
The following example code initializes a Calendar using the default time zone and prints the system's current time to console.
#include once "kiwi\kiwi.bi"
#include once "kiwi\time.bi"
' Initialize a Calendar using the default/system's time zone
Dim systemCalendar as Calendar = Calendar()
' Initialize a new DateTime, assign the system's current DateTime
' to it and print time to console
Dim computerTime as DateTime = systemCalendar.getTime()
print "System's Time: " & computerTime.toString()
The following code example initializes calendars for different time zones and prints the time of those zones to the console.
#include once "kiwi\kiwi.bi"
#include once "kiwi\time.bi"
' Prints System's current date time
Dim systemCalendar as Calendar = Calendar()
Dim computerTime as DateTime = systemCalendar.getTime()
print "Your computer's Date Time is " & computerTime.toString()
' Prints current date time in Athens/Greece
Dim athensGreeceCalendar as Calendar = Calendar(+3) '+3 UTC Time Zone
Dim timeInGreece as DateTime = athensGreeceCalendar.getTime()
print "Date Time in Athens/Greece is " & timeInGreece.toString()
' Prints current date time in Berlin/Germany
Dim londonCalendar as Calendar = Calendar(+2) '+2 UTC Time Zone
Dim timeInLondon as DateTime = londonCalendar.getTime()
print "Date Time in Berlin/Germany is " & timeInLondon.toString()
The following code example initializes calendars for different time zones and converts a UTC Timestamp to their Time Zone.
#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
Dim utc0Calendar as Calendar = Calendar(0)
Dim utcTime as DateTime = utc0Calendar.createTime(timeStampUTC)
print "Timestamp to UTC +0 TimeZone: " & utcTime.toString()
' Convert the timeStampUTC to your computer's timezone
Dim systemCalendar as Calendar = Calendar()
Dim computerTime as DateTime = systemCalendar.createTime(timeStampUTC)
print "Timestamp to System's TimeZone: " & computerTime.toString()
' Convert the timeStampUTC to Athens/Greece timezone
Dim athensGreeceCalendar as Calendar = Calendar(+3) '+3 UTC Time Zone
Dim timeInGreece as DateTime = athensGreeceCalendar.createTime(timeStampUTC)
print "Timestamp to Athens/Greece TimeZone: " & timeInGreece.toString()
' Convert the timeStampUTC to Berlin/Germany timezone
Dim londonCalendar as Calendar = Calendar(+2) '+2 UTC Time Zone
Dim timeInLondon as DateTime = londonCalendar.createTime(timeStampUTC)
print "Timestamp to Berlin/Germany TimeZone: " & timeInLondon.toString()
- MySQL/MariaDB - Coming to v1.0.2
- ArrayList
- Comparator
- HashMap - Coming to v1.0.2
- Queue