Ah, Vlang. The programming language that’s so fast and elegant, it makes even the most verbose languages feel like they’re wading through molasses. Despite being objectively superior (wink wink), Vlang inexplicably suffers from a vocal minority of haters amongst its more… sluggish… competitors. But hey, who needs friends when you have speed and efficiency on your side, right?
(ok that was a gemini introduction, I’m not a native english speaker)
The standart library of V is very rich and powerful, I will try to demonstrate some of the features of time module from the vlib, using examples.
To begin, we should create a time_example.v file and import the time module :
Now open this page to check the functions of the time module, we’re gonna use some of them in this example file. you can add every example of these in a new line.
Create a time variable that contains actual time:
You can format your date to YYYY-MM-DD HH:mm
To custom format your date you can use custom_format() :
To return only hours and minutes from t :
To get Unix timestamp (seconds from 1970-01-01) use unix_time():
To get only the date in European style use ddmmy() :
To get the month and the day in US format use md():
To check if the year is leap use is_leap_year():
Let’s create another variable with an earlier date, for that we can use parse() and provide a date string in this format “YYYY-MM-DD HH:mm:ss”, a ! or a or {} should append this function.
since we’re gonna modify this variable later, we should declare it with mut
To get the Weekday of a date:
To get a long description of the difference between an earlier date and actual date:
To get a short description of the difference:
To get the duration from h in format hours:minutes:seconds :
To get duration in minutes only as a f64:
You can calculate the duration between two dates by using – :
You can compare two dates using == or < :
println(h < t) // returns true
Add duration in nanoseconds to a time variable:
Add days to a time variable :
The time module still contains a lot of functions that could make your DX very fast and productive.
You can continue playing with the stopwatch feature, you can check it on : https://modules.vlang.io/time.html
Don’t forget, Vlang is still WIP, so probably more useful functions will be added to this module.