You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/groovy/2021-05-11-determine-a-datatype-in-groovy.md
+5
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,8 @@ class java.util.ArrayList
42
42
class java.lang.String
43
43
java.lang.String
44
44
```
45
+
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/1c12a2e35d8803106d4cf2b0e11f6b18#file-determine-datatype-groovy)
46
+
45
47
In the above program, we can see that the `names` is an `ArrayList` and `blogname` is a `String` object.
46
48
47
49
When we call the `getClass()` method on these objects it prints its respective datatype.
@@ -68,6 +70,7 @@ Output:
68
70
true
69
71
false
70
72
```
73
+
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/eafc65547cd3cd54877ca5d54eec8acc)
71
74
72
75
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.
73
76
@@ -92,6 +95,8 @@ That's it about checking the datatype of an object in Groovy.
92
95
93
96
If you know any other way to check the datatype of an object, please comment below to help the community. Thank you.
94
97
98
+
You can check my YouTube channel [here](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w)
99
+
95
100
### Related Articles
96
101
97
102
-[Hello World In Groovy](https://coderolls.com/hello-world-in-groovy/)
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/a965f1a078d382ff7366e7ba6d13561c)
124
+
121
125
### Explanation:
122
126
123
127
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:
158
162
```
159
163
Instant To Timestamp: 2021-05-13 21:07:44.381
160
164
```
165
+
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/ea3bc951f15be0010569d306ccafa975)
166
+
161
167
### Explanation:
162
168
163
169
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:
199
205
```
200
206
Timestamp To Instant: 2021-05-13T15:39:08.046Z
201
207
```
208
+
See above code as [GitHub Gist](https://gist.github.com/gauravkukade/a031b1904d4efaf758a59462ee2dc02e)
209
+
202
210
### Explanation:
203
211
204
212
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.
267
275
268
276
We will see how to get the current date-time in java. Also, we will see how we can format them using the SimpleDateFormat.
269
277
270
-
You can check my YouTube channel at: https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w
278
+
You can check my YouTube channel [here](https://www.youtube.com/channel/UCl31HHUdQbSHOQfc9L-wo3w)
0 commit comments