author | mbaesken |
Thu, 28 Nov 2019 13:02:39 +0100 | |
changeset 59323 | ae2eb76c486d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
31096
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
1 |
# usage: jjs secondssince.js |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
2 |
|
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
3 |
/* |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
4 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
5 |
* |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
6 |
* Redistribution and use in source and binary forms, with or without |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
7 |
* modification, are permitted provided that the following conditions |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
8 |
* are met: |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
9 |
* |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
10 |
* - Redistributions of source code must retain the above copyright |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
11 |
* notice, this list of conditions and the following disclaimer. |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
12 |
* |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
13 |
* - Redistributions in binary form must reproduce the above copyright |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
14 |
* notice, this list of conditions and the following disclaimer in the |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
15 |
* documentation and/or other materials provided with the distribution. |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
16 |
* |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
17 |
* - Neither the name of Oracle nor the names of its |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
18 |
* contributors may be used to endorse or promote products derived |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
19 |
* from this software without specific prior written permission. |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
20 |
* |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
21 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
22 |
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
23 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
24 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
25 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
26 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
28 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
29 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
30 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
31 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
32 |
*/ |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
33 |
|
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
34 |
// Number of seconds elapsed since the specified Instance #nashorn #javascript #java |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
35 |
// Input date and time in ISO 8601 format |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
36 |
// Example: 2001-01-01T00:00:00Z for 1 Jan 2001, 0 GMT |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
37 |
|
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
38 |
var Instant = java.time.Instant; |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
39 |
var ChronoUnit = java.time.temporal.ChronoUnit; |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
40 |
print("Enter date time:"); |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
41 |
var sec = Instant.parse(readLine()). |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
42 |
until(Instant.now(), ChronoUnit.SECONDS); |
a3a697c1edd5
8085937: add autoimports sample script to easily explore Java classes in interactive mode
sundar
parents:
diff
changeset
|
43 |
print(sec); |