Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2021
Merged
Changes from all 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
5 changes: 5 additions & 0 deletions _posts/groovy/2021-05-11-determine-a-datatype-in-groovy.md
Original file line number Diff line number Diff line change
@@ -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.
@@ -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.

@@ -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/)
Original file line number Diff line number Diff line change
@@ -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.
@@ -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()`.
@@ -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.
@@ -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 ).
@@ -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 channel at: https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w
You can check my YouTube channel [here](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w)

### Related Articles