In Python, using the timedelta object is the easiest way to calculate number of days between two given dates.
Using timedelta
If you have two date objects, you can just subtract them, which computes a timedelta object.
In this program, we will cal...
In Python, there are 3 ways to get current time in milliseconds.
Using time Method
The time.time() method returns the time in seconds since the epoch as a floating point number. For example,
#!/usr/bin/python3
# Import module
import time
ms =...
In Python, there are 2 ways to get the day of week given a date.
Using weekday Method
The weekday() method returns the day of the week as an integer, where Monday is 0 and Sunday is 6.
The following example should cover whatever you are trying to ...
In Golang, there are 2 ways to get the difference in hours between two dates.
Using time.Since Function
The time.Since() function returns the time elapsed since t. It is shorthand for time.Now().Sub(t). For example,
package main
import (
"fm...
In Golang, there are 2 ways to validate URL with standard package.
Using ParseRequestURI Function
url.ParseRequestURI parses a raw url into a URL structure. It assumes that url was received in an HTTP request, so the url is interpreted only as an ab...
In Python, using the timedelta object is the easiest way to subtract a day from a date.
Using timedelta Object
A timedelta object represents a duration, the difference between two dates or times.
See the following example:
#!/usr/bin/python3
#...
In Python, there are 3 ways to get file creation and modification dates times.
Using os.path Function
The os.path.getmtime() function returns the time of last modification of path.
The os.path.getctime() function returns the system’s ctime which, o...
In Rust, there are 3 ways to iterate over a string by character.
Using chars Method
The chars() method returns an iterator over the chars of a string slice. See the following example:
fn main() {
let s = "abc";
for c in s.chars() {
pr...
In Rust, there are 3 ways to update a value in a mutable HashMap.
Using get_mut Method
The get_mut() method returns a mutable reference to the value corresponding to the key. See the following example:
use std::collections::HashMap;
fn main()...
In Python, there are 2 ways to get the current time.
Using datetime Module
The datetime module supplies classes for manipulating dates and times. See the following example:
#!/usr/bin/python3
# -*- coding: utf8 -*-
# Import module
import datet...
In Golang, there are 2 ways to remove duplicates strings from slice.Using a Hash Map
We have defined a function where we are passing the slice values and using the map function we are checking the duplicates and removing them. The ones that are curr...
In Golang, there are 2 ways to install Go in Linux.Download Packages
Download packages for Windows 64-bit, macOS, Linux, and more.
Go install
Linux
Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extr...
In Rust, there are two ways to install rust in Linux.Running the following in your terminal
If you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen i...
In Golang, there are two ways to get the start and end date of the current month.Using time.AddDate Function
AddDate returns the time corresponding to adding the given number of years, months, and days to t. For example,
package main
import (
"fm...
In Golang, there are two ways to format the time.The layout string
Go doesn’t use yyyy-mm-dd layout to format a time. Instead, you format a special layout parameter.
2006-01-02 15:04:05.999999999 -0700 MST
package main
import (
"fmt"
"tim...