Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update groovy object datatype and java timestamp blogpost#27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gauravkukade merged 1 commit intomasterfromupdate-blogpost
May 14, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,6 +42,8 @@ class java.util.ArrayList
class java.lang.String
java.lang.String
```
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/1c12a2e35d8803106d4cf2b0e11f6b18#file-determine-datatype-groovy)

In the above program, we can see that the `names` is an `ArrayList` and `blogname` is a `String` object.

When we call the `getClass()` method on these objects it prints its respective datatype.
Expand All@@ -68,6 +70,7 @@ Output:
true
false
```
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/eafc65547cd3cd54877ca5d54eec8acc)

In the above program, I have defined one String `blogname`. I have used the `instanceof` keyword to check if the `blogname` implements the `String` class and it prints `true`. It means the `blogname` is an instance of the `String` class.

Expand All@@ -92,6 +95,8 @@ That's it about checking the datatype of an object in Groovy.

If you know any other way to check the datatype of an object, please comment below to help the community. Thank you.

You can check my YouTube channel [here](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w)

### Related Articles

- [Hello World In Groovy](https://coderolls.com/hello-world-in-groovy/)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,6 +74,8 @@ Output:
4. timeStampMillis: 1620919459988
5. timeStampSeconds: 1620919459
```
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/b1ceabac137864efd7258b60610cd9dd)

### Explanation:

1. In the first case, we have used the `.now()` method of the `Instant` class to get the current timestamp.
Expand DownExpand Up@@ -118,6 +120,8 @@ Output:
2. timestampFromDateObject: 2021-05-13 20:55:44.187
```

See above code as [GitHub Gist](https://gist.github.com/gauravkukade/a965f1a078d382ff7366e7ba6d13561c)

### Explanation:

1. In the first case, we are got the `timestamp` using the system time in milliseconds. We can get the system time in millisecond using the `System.currentTimeMillis()`.
Expand DownExpand Up@@ -158,6 +162,8 @@ Output:
```
Instant To Timestamp: 2021-05-13 21:07:44.381
```
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/ea3bc951f15be0010569d306ccafa975)

### Explanation:

In the above example, we have used `.from()` of the `Timestamp` class to get the current timestamp from the `instant` object.
Expand DownExpand Up@@ -199,6 +205,8 @@ Output:
```
Timestamp To Instant: 2021-05-13T15:39:08.046Z
```
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/a031b1904d4efaf758a59462ee2dc02e)

### Explanation:

In the above example, we have used the `.toInstant()` method on the `timestamp` object to get the current timestamp (as Instant ).
Expand DownExpand Up@@ -267,7 +275,7 @@ If you have any queries about the above article, please comment below. Thanks.

We will see how to get the current date-time in java. Also, we will see how we can format them using the SimpleDateFormat.

You can check my YouTube channelat:https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w
You can check my YouTube channel[here](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w)

### Related Articles

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp