Trending March 2024 # How Linux Date Command Works? # Suggested April 2024 # Top 12 Popular

You are reading the article How Linux Date Command Works? updated in March 2024 on the website Cancandonuts.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 How Linux Date Command Works?

Introduction to Linux Date

In the Linux ecosystem, the date prints or displays the current date and system time zone. With the help of the date command, we can print the date and time in a different format. The date commands provide the liberty to print past and future dates also. David MacKenzie wrote the date command utility.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax of Date Command:

date [OPTION]... [+FORMAT]

date: We can use the date keyword in the syntax or command. It will take the two-argument as an option and format type (to which we need to print the date). Provide the end result with the requested format date.

OPTION: We can provide the different flags as options that are compatible with the date command.

FORMAT: As per the requirement, we can pass the different types of date formats to the date command.

How does Linux Date Command work?

The date command can print different type date formats. By default, the date command will print the date as per the time zone configured in the UNIX or Linux operating system. We can also change the system time zone and print the different time zone dates. For changing the time zone, you should have the root privileges. Generally, the date command will take the two sets of arguments like option and date format. As per the inputs provided to it, it will manipulate the data and provide the date and time output in the request format.

Below is the list of formatting keywords which are commonly used with the date command:

%a: It will display the weekday name example: Mon.

%A: It will display the full weekday name example: Monday.

%b: It will display the short month name example: Jan.

%B: It will display the long month name example: January.

%d: It will display the date of the month example: 01.

%H: It will display the hour digit in 24hr format.

%I: It will display the hour digit in 12hr format.

%j: It will display the date of the year example: 001..366.

%m: It will display the month in digit format example: 01..12.

%M: It will display the minute value example: 00..59.

%S: It will display the second value example: 00..60.

%y: It will display the last two digits of the year example: 20.

%Y: It will display the year example: 2023.

Examples of Linux Date

Given below are the examples mentioned:

Example #1

Date Command

Code:

date

Explanation:

As per the above command, we are able to print the system time and date.

It will print the day (in short format), month (in short format), date, time (include the hour, minute, and seconds), time zone (IST), and year (2024).

Output:

Example #2

Date String

a. Date Command – Custom Format

The date command is very flexible, we can provide different custom inputs to the date command, and it will print the date format accordingly. We have the privilege to change the default date format to get the result in our own format.

Code:

Explanation:

As per the below screenshot, we have printed the custom date. As per the requirement, we can add different special characters also.

Output:

b. Date Command – String Format

In the date command, we have the functionality to pass the string parameters. Accordingly, the date command will print the output. It will not require following the date input format.

Code:

date -d "last month"

Explanation:

We can add the string option with the date command. It is a quick way to display the dates.

Output:

Example #3

Override the Time Zone

a. Date Command – With Different Time Zone

In the date command, we are able to display the time and date in different time zones.

Code:

TZ='Africa/Djibouti' date

Explanation:

Using the “timedatectl list-timezones” command, we are able to find the list of time zones available in the Linux.

As per the requirement, we can choose any time zone and pass the values to the TZ variable.

b. Date Command – Use Epoch Time Converter

The epoch timestamp is also called the UNIX timestamp. In this conversion, the date command is to use the epoch converter. It will calculate the number of seconds that have elapsed from January 1, 1970 at 00:00:00 UTC.

Code:

date +%s

Explanation:

We are able to calculate the time between the epoch timestamp and the current timestamp. The time difference will be in seconds.

Output:

c. Date command – With File Operation

In the Linux environment, we can use the date command differently. Here, we are able to find the last modification time of the file. We need to use the “-r” option with the command to get this timestamp.

Code:

date -r /etc/passwd

Explanation:

As per the screenshot below, we can find the last modification time of the file “/etc/passwd”.

Output:

d. Date Command – Display Past Date

In the date command, we have the functionality to display the past date in different formats.

Code:

date --date="2 day ago"

As per the above command, we are able to print the past 2 day’s date and time.

Output:

e. Date Command – Display Future Date

In the date command, we have the functionality to display the future date in different formats.

Code:

date --date="2 day"

Explanation:

As per the above command, we are able to print the future 2 day’s date and time.

Output:

f. Date Command – Set System time and Date

With the help of the date command, we are able to set the required time in the system.

Note: It is not recommended to set the timestamp manually. In Linux, the server clock is coordinated using the ntp service or the systemd-timesyncd service.

Code:

date --set="20240101 17:30"

Explanation:

With the help of the date command, we are able to set the system time. We have set the manual time i.e. 01/01/2024 05:30 PM.

Output:

Conclusion

We have seen the uncut concept of “Linux Date Command” with the proper example, explanation, and command with different outputs. The date command displays the date and time in a different format. It will be widely used in shell and application jobs.

Recommended Articles

We hope that this EDUCBA information on “Linux Date” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

 Linux More Command

Linux Touch Command

Linux tr Command

Linux tee Command

You're reading How Linux Date Command Works?

How Count Command Works In Mongodb? (Examples)

Introduction to MongoDB count

MongoDB count is used to counting the no of a document from collections. We have found the number of documents using the count method in MongoDB. If we have used find method to show the data of collections, it will show all the data, but instead of finding if we have used count, it will display the only actual count of documents. The count is significant and useful to find the actual count of documents. It is beneficial in a large document of collections to find the no of documents only instead of displaying all the data.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax with parameters:

collection_name.count ()

collection_name.count (query, options)

Parameters with count query in MongoDB:

Below is the parameter description of the above syntax:

Collection name: Collection name is used to display the count of documents from the collection. Collection parameter is more important.

Count: It is used to count the no of the document from collections, we have found the number of documents using the count method.

Query: We can use a specified query to find the count of documents mentioned in the query. Using the query, we have filtered the results of documents from collections.

Limit: Limit is an optional parameter of the count method. We can return the maximum number of counts from the collection using limit.

Skip: Skip is an optional parameter of the count method. We can skip the number of matching documents before returning the result of the count of collection documents.

Hint: Hint is an optional parameter. This specifies that the index name is either string or either it is documented.

Read concern: Read concern is an optional parameter. The level is specified that the default level of real concern.

It has the following syntax:

Collation: Collation is used to the operation of count in MongoDB. Collation is an optional parameter of the count method.

How count Command works in MongoDB?

Below is the working of count method in MongoDB.

MongoDB count is used to counting the no of the document from collections.

We have found the number of documents using the count method in MongoDB.

The count is significant and useful to find the actual count of documents.

It is handy in a large document of collections to find the no of documents only instead of displaying all the data.

If we have used find method to show the data of collections, it will show all the data.

But instead of finding, if we have use count, it will display the only actual count of collection.

We can define read concern levels as local and majority. If we want to a read concern level as the majority, then we need to specify a nonempty query condition.

The default override read concern level of count method in it is local.

We can skip the count of collection documents using the skip parameter. Skip is used to skip the count of documents.

We have also used the index to return the count of the documents. For fast retrieval count of documents, we are using an index with count method.

Count method is essential and useful to display the count of all or specified documents.

Examples of MongoDB count

Given below are few of the examples:

We are taking the example of the emp_count table to describe the example of the count method in MongoDB. Below is the data description of emp_count table as follows.

Code:

db.emp_count.find ()

Output:

Example #1 – Count all documents from a collection

In the below example, we have count all documents from emp_count table using count method in MongoDB.

db.runCommand( {count: ’emp_count’ } )

Output:

The count of all the documents in emp_count table is 12. We have to find a count of documents in two ways.

Example #2 – Count documents that match a query

In the below example, we have to count the documents that match query from emp_count table using count method in MongoDB.

Code:

db.runCommand ( {count:’emp_count’, query: { emp_salary: { $gt: 10000 } } } )

Output:

In the above example, the match count of query greater than 30000 emp_salary is 4, and greater than 10000 emp_salary is 11.

Example #3 – Skip documents in the count

Code:

db.runCommand ( {count:’emp_count’, query: { emp_salary: { $gt: 10000 } }, skip: 10 } )

Output:

Example #4 – Count using default read concern

Below is the example of count using default read concern in MongoDB. We have used read concern levels as local to display the result.

Code:

db.runCommand( { count:'emp_count', query: { emp_salary: { $gt: 10000 } }, readConcern: { level: "local" } } )

Output:

Recommended Articles

This is a guide to MongoDB count. Here we discuss the Introduction, how count command works in MongoDB? Along with examples. You may also have a look at the following articles to learn more –

Linux Desktop: Command Line Vs. User Interface

In the Linux desktop world, the graphical user interface is here to stay. Old Unix hands may grumble, but the fact remains that, without all the efforts poured into GNOME, KDE, Xfce and others, Linux would not be as successful as it is today.

The reason for the desktop’s success is obvious. A desktop requires much less knowledge than a command line, and is suited to maybe 80% of the most common tasks that an average user needs. If the desktop needs much larger applications, that hardly seems a problem on a modern computer.

In fact, for many administrative tasks, the command line is actually easier than the desktop. Looking through my BASH history, I can see at least five circumstances in which I generally choose the command line over the desktop:

Whether you are copying, moving, or deleting files, the BASH shell gives you far more options than KDE’s Dolphin or GNOME’s Nautilus. Such desktop file managers do their best, but they can only plan for the average use cases, and add confirmation dialogs to prevent users from doing something rash.

Moreover, because menu and toolbars rarely have entries for symbolic links, a whole generation of desktop users are unaware that the possibility even exists, or when to use them.

By contrast, consider all the possibilities of a simple command such as cp (copy). To start with, you can decide whether you want an indication of progress, or the ability to confirm before overwriting files. If you want you can archive or backup files. You can choose to create symbolic links instead of copying, and whether to preserve file attributes, and you can ensure that you remain on the same filesystem or not. Other file management commands are similarly versatile, although some of the details differ.

Another practical consideration is that, when moving large numbers of files — for instance, when you are doing a backup — desktops tend to freeze, no matter how much RAM your machine has. Consequently, you can be left waiting for your file management to complete, unable to do anything else. Or, even worse, you can be left uncertain whether you have actually succeeded what you are doing. These problems simply don’t exist at the prompt.

Just as with the file management commands, the ls command gives you far more versatility than any desktop display. True, by definition you can’t have an icon view, but you can you use colors or symbols to indicate different types of files.

You also have all the filters available in desktop file managers, including whether to show hidden and backup files, as well as the ability to sort listings by extension, file size, time modified, and file version.

However, what I appreciate most about ls is that when you use the -l or -g option, all the information about file attributes is printed on a single line.

By contrast, in the average desktop file manager, you choose the default attributes to display, or at least their order (which, in anything less than a full-sized window, often comes down the same thing). Often, too, permissions are listed on a separate tab, and four or five keystrokes away.

Some applications simply defy a graphical interface. Oh, you can make one, if you insist, but the result is always proof (if you need any) that slapping everything into a window does not necessarily make for user friendliness.

That is especially true of applications with hundreds of options, such as Apache. However, it can also be true of much smaller utilities such as crontab. I have yet to see a crontag graphical interface that was not more intimidating than the command itself. By the time I have finished deciphering a desktop of crontab, I could have scheduled half a dozen jobs to run at a latter time.

Both apt-get and yum, the leading package management tools, have had graphical front ends for years. However, just as with file managers, you can practically hear graphical package tools like Synaptic or the Ubuntu Software Centre grinding away when processing large numbers of files. In fact, when you update, many of these desktop tools simply freeze — often while giving very little indication of what is happening.

Moreover, if you want to install something too soon after you log in, often the graphical tools have a conflict with the update applet. When that happens, you either have to wait or decide which one to close.

Next Page: Command line and desktop resources….

How To Check Ntfs Permissions Using Command

In Windows 11/10, you can view NTFS permissions in different ways. Many third-party tools or software are available that will help you check NTFS permissions on your Windows computer. In addition to this, you can also use the command line tool. In this article, we will show you how to check NTFS Permissions using Command-line or Tool.

How to check NTFS Permissions using Command-line or Free tools

To check NTFS Permissions using Command-line or Tool, you can use Windows PowerShell and other free software. We have listed all these tools below.

Windows PowerShell

Microsoft’s AccessEnum

Folder Security Viewer

Permissions Reporter from Key Metric Software

NTFS Permissions Reporter from CJWDEV

Let’s see how to use all these tools to check NTFS permissions on Windows 11/10.

1] Windows PowerShell

Windows PowerShell is a built-in command line tool that comes pre-installed in all Windows computers. You can use this tool to check NTFS permissions. The command that is used to check NTFS permissions in PowerShell is Get-Acl. We will explain here how to use this command in PowerShell in different scenarios.

First of all, launch Windows PowerShell. There are different ways to open Windows PowerShell. The easiest method is to open it via Windows Search.

You can use the Get-Acl command with and without parameters. If you use it without any parameters, Windows will show you the NTFS permissions for the current working directory. For example, if I want to check the NTFS permissions for the folder located inside my D drive, the command is:

Get-Acl D:foldername

Replace the folder name in the above command with the name of your folder. If the folder name has spaces, you have to type it in quotations. For example, if the folder name is New folder, then the command will become:

Get-Acl D:"New Folder"

Now, let’s see how to use the Get-Acl command with different parameters. In all the commands, we will use the New folder as the folder name. Replace the New folder with the name of your folder.

If you use the Format-List parameter, you will see the detailed permissions as shown in the above screenshot. The command Get-Acl with the Format-List parameter is as follows:

The Select -ExpandProperty Access or .Access parameters give you a more detailed view of NTFS permissions, like file system rights, access control type, inheritance flags, etc. (refer to the above screenshot). Both the parameters give you the same result but commands to use both these parameters are different. The commands are given below:

(Get-Acl D:"New Folder").Access

You can use any of the above commands to get more detailed NTFS permissions.

The parameter ft -AutoSize gives the NTFS permissions output in a table format. The command Get-Acl with the ft -AutoSize parameter is used as follows:

If you want to see the NTFS permissions for a particular user name or group, say, Administrators, SYSTEM, Authenticated users, etc, you have to specify it in the command while using the ft -AutoSize parameter. The command for this is:

In the above command, replace the user name or group with the respective names. For example, if you want to see the NTFS permissions for Administrators, you have to type the following command:

In the above screenshot, I have used the above command for three different user names, users, SYSTEM, and Authenticated users.

2] Microsoft’s AccessEnum

You can save the permissions on your disk in text format. The “Compare to saved” is one interesting feature of this free software using which you can compare the permissions of the currently scanned directory or registry path with the saved permissions file.

Read: The Volume Bitmap is incorrect when running CHKDSK

3] Folder Security Viewer

Folder Security Viewer is available as free and paid software. Its free version comes with limited features, You can use it to view the NTFS permissions for free. Under the Home tab, you will see different options, including Permission Report, Folder Report, Owner Report, etc.

To download Folder Security Viewer, visit chúng tôi You have to provide your name and email address in order to download the software. In your email, you will also receive a free trial 14 days license. After the trial license expires, you can still use its free version.

4] Permissions Reporter from Key Metric Software

Permissions Reporter is a free tool from Key Metric Software to check NTFS permissions on Windows 11/10. It is available in both free and paid versions. Its free version allows you to view NTFS permissions and access some features. If you want to access all its features, you have to purchase its license.

The Folder Tree tab shows the tree view of the selected directory. The Folder Permissions tab shows the permissions of all the folders inside the directory in a list view. You can also apply filters to get more specific results. The Export option is also available. But in the free version, you can export the project only in HTML format.

5] NTFS Permissions Reporter from CJWDEV

What are the basic NTFS permissions?

The basic NTFS permissions include Full Control, Read and Execute, Modify, Read, Write, etc. You can check these permissions by opening the properties of a particular folder or drive. After opening the properties, go to the Security tab. You will see all these permissions there. In addition to this, you can also use free software and Windows PowerShell to view NTFS permissions.

Read next: How to take full Ownership of Files & Folders in Windows .

How Schema Works In Mongodb?

Definition of MongoDB schema

MongoDB schema basically used in command-line tool or we can use it programmatically in our application at a module level. As we already know MongoDB is schema-less, at the time of creating any objects we cannot create any schema in MongoDB. We can enforce the schema for collection in MongoDB by using the MongoDB atlas cluster, for enforcing the document schema we need first to connect the database and collection. We can also create schema structure of collection by using create collection command, also we can check the index and collection field in MongoDB.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax:

Below is the syntax of the MongoDB schema.

1) To show the schema of index collection –

2) To show the schema of collections –

for (var key (Used to show key fields) in schematodo (Used to display schema field of collections)) { print (key, typeof key) ; }

3) Schema structure of document –

}

Parameter Description:

1) Name of collection – This is defined as the name of collection from which we have checked the schema structure of collection and indexes. We can check the schema structure of any collection in MongoDB.

2) getIndices – This is the method in MongoDB used to display schema structure of all indexes from specified schema which was we have used in our command.

3) findOne – This method is used to find single documents from collections. Using this method we also find all collection fields in MongoDB.

4) schematodo – This is used to display the schema structure of database collection in MongoDB. Using schematodo we can display all fields from collections.

5) Key – This parameter is defined as print the field from the specified collection which was we have used in our query.

6) Type of key – This parameter is defined as a type of key which was we have used in the query to display the schema structure.

7) Properties – This parameter is defined as the property of the document field which was we have used in our query.

8) Field name – This is defined as the name of the field which was we have used in our query. Using field name we can retrieve the document structure.

9) BSON type – This is defined as the document type which was we have used in the collection.

How schema works in MongoDB?

MongoDB is schema-less structure but we can enforce the collection by defining the document schema.

Schema is nothing but regular documents which was adhered to like the same specification of JSON schema.

We can also validate the schema in the MongoDB server. We can also use the type key to control the collection field value.

In MongoDB, document schema will represent any of the BSON type operators. We can define the schema structure of the following types.

10) UUID

To display the schema of indexes in MongoDB we need to first connect to the specific database. The below example shows that we need to connect the database to display the structure of indexes.

Code:

db.MongoDB_Update.getIndices ()

Figure – We need to connect the database to display the structure of indexes

In the above example when the first time execution of the query we have not connected to the database, so it will not show the result of the query. But after connecting to the specified database we can see the schema of indexes in MongoDB.

Binary encoded superset will support the additional data types in MongoDB.

We can enforce the document schema using MongoDB atlas. To create the enforcing schema first we need to connect the database and collections.

We don’t create a collection with schema in MongoDB, we can create an empty collection in MongoDB.

At the time of inserting documents, MongoDB automatically creates the schema for the collection.

We can say that MongoDB is schema-less database but we can implement our own class in our program to restrict the collection before inserting any data into the collection.

Example

Below example shows that enforce collection document schema using MongoDB atlas. We have used the below steps to enforce document schema.

1) Create a new application or open the existing application

Figure – Example to create new application to enforcing schema.

2) Add the collection and database

Figure – Example to add collection and database.

We have added the sample_training database and grades table to the application.

Figure – Check collection and database added to the application.

3) Generate schema

Figure – Generate schema.

4) Run the validation on generated schema

In the below example we have to check our validation on grades collection is working or not.

Figure – Example to run validation on schema.

5) Display the index schema details

In the below example, we have displayed the schema structure of indexes. We have displayed all the indexes structures from MongoDB_Update collections.

Code:

db.MongoDB_Update.getIndices ()

Figure – Example to display index schema structure details.

6) Display the schema fields from collections

In the below example, we have a display the schema of the collection. We can see that all the fields from MongoDB_Update fields will be displayed.

Code:

for (var key in schematodo) { print (key, typeof key) ; }

Figure – Example to Display the schema fields from collections.

Conclusion

Basically, MongoDB is schema-less database, we cannot create schema in MongoDB, but we enforce the collection documents in application code or using MongoDB atlas GUI tool. For generating schema first we need to connect to the specified database and collections in MongoDB.

Recommended Articles

This is a guide to Mongodb schema. Here we discuss the definition, How schema works in Mongodb? along with examples respectively. You may also have a look at the following articles to learn more –

How Unit Works In Kotlin

Introduction to Kotlin Unit

Kotlin unit is one of the return types and it returns null as the value similar to void but Unit is used to return type of any function that does not return any values and it is the optional one so the values are mentioned as the Unit in the return type apart from void Unit is the real class and is also called as Singleton so with only one instance is acceptable for accessing the application wherever its needed unit also the kotlin library so that unit will be applicable for argument type of the one value.

Start Your Free Software Development Course

Syntax of Kotlin Unit

Kotlin has many default keywords, classes and methods for implementing the application. Like that unit is one of the class types and it is used in the object class which means it is in the singleton class having only one object.

{ } —method overridden and declarations— }

The above codes are the basic syntax for to utilising the unit keyword and it is used in the return type of the classes and functions on the script.

How does Unit work in Kotlin?

The unit in kotlin it corresponds to the void return type which is similar to the java language. Generally, void means it returns null has the value and it passed as the argument type and return type. Unit is the return type of any function that does not return any meaningful values and it is optional to mention the Unit as the return type in the kotlin functions.

Mostly unlike void as the return type and unit is the real class which is mentioned as the singleton instance with only one instance for to call entire areas in the application. And also Unit is equivalent to the void type in the java language so we can explicitly add the unit as the return type for functions that returns null as the value and argument which is used with the other areas of the kotlin codes.

Mainly the Unit class can’t extend with other types and classes which is needed or not there is no option to perform this feature so it fully acts as the private modifiers. So that Unit is the default return type and it is declared as the optional therefore the function is also valid and calls in other areas. The unit has executed all types of jvm and js for common types with only one value using the Unit object.

Examples of Kotlin Unit

Given below are the examples mentioned:

Example #1

Code:

class TouristMonths { val mnths = listOf(“January”, “February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”) val elects = listOf(“Ups”,”Inverters”,”Gadgets”,”Desktop PCs”,”Microwave Oven”,”Fridge”,”Washing Machine”,”mobile”) val lap = listOf(“Dell latitude”, “dell inspiron”,”sony”,”acer”,”samsung”,”lenovo”,”apple”) val placesvisited = listOf( States(“Delhi”, listOf(Tourist(“Noida”, lap), Tourist(“Darjeeling”, mnths))), States(“Tamilnadu”, listOf(Tourist(“Chennai”, elects)))) } data class Customers( val custname: String, val custid: Int ) enum class Banks ( val names: String, val id:Int, val sno:Int ) { First(“PNB”,1,123), Second(“IOB”,2,466), Third(“SBI”,3,7898), Four(“RBL”,4,7885), Five(“Indian”,5,798), Six(“Indusland”,6,124453), Seven(“HDFC”,7,984); } fun operations(): Unit { println(“Your kotlin unit first example “) } println(“Welcome To My Domain your listed banks are as follows:”) operations() var trt=TouristMonths() println(“#############################################################”) println(“Welcome To My Our tourist services”) println(“Its the first example that related to the kotlin Unit example”) println(“#############################################################”) println(“First we passed the input as Arrays”) val arnum = arrayOf(8, 3, 4, 2,1,5,9,7,6) arnum.forEach { println(it) } val usr = arrayOf(Customers(“sivaraman”, 32), Customers(“raman”, 23), Customers(“arunkumar”, 16)) usr.forEach { println(it) } println(“We used forEach loop for handling collection datas”) val inp = listOf(1, 4, 3, 2) inp.forEach{println(it)} val numusras = listOf(Customers(“xx”, 42), Customers(“yy”, 44), Customers(“xx zz”, 46)) numusras.forEach { println(it) } println(“We used forEach loop with collection class called HashMap and its methods”) val hshmap = hashMapOf(32 to “kunju”, 12 to “moanan”, 54 to “sevela” ) hshmap.forEach{ println(it) } val map2 = hashMapOf(“kumar” to Customers(“kumar”, 15), “arun” to Customers(“arun”, 16), “arun kumar” to Customers(“arun kumar”, 16)) map2.forEach{ println(it) } }

In the above example, we used kotlin codes but return type as Unit on the output console screen. Here we used some enums, classes and classes like collections. Using enums we can declare the values and utilised the values in the main method wherever requires. The list interface is the collection interface and it stores and retrieves the datas.

Example #2

Code:

val mnthstrs = "January is the first month, February is the second month, march is the third month, april is the fourth month, may is the fifth month, june is the sixth month, july is the seventh month, august is the eight month, September is the ninth month, october is the tenth month, November is the eleventh month, december is the twelth month" fun operations(): Unit { println("The month details are: " + mnthstrs) } fun main() { println("Welcome To My Domain its the second example that related to the kotlin unit") operations() }

Output:

Example #3

Code:

fun firstMethod(str:String): Unit{ println("Your first kotlin method for the Unit concept") println(str) } println("Your second method for the Unit") demo(str1) } println("Welcome To My Domain its the third example that related to the kotlin Unit") secondMethod("Your input key is string: Thank you users for spending the time",::firstMethod) }

Output:

In the final example, we used Unit type to convert the values to the string type. Here we used both Unit and another datatype as the parameter and it will call in the main.

Conclusion

In kotlin language has a lot of concepts and features for implementing the applications with more sophisticated. Like that Unit is one of the kotlin concepts and it is used in the various areas of the script and it combines with the other data types to perform the user operations in the task.

Recommended Articles

This is a guide to Kotlin Unit. Here we discuss the introduction, syntax, and working of a unit in kotlin along with different examples for better understanding. You may also have a look at the following articles to learn more –

Update the detailed information about How Linux Date Command Works? on the Cancandonuts.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!