How to pass an Instant from a javascript app to a spring-data-rest API
I have a spring-data-rest API and I create a query like so:
@Query("SELECT at FROM Transaction at WHERE at.transactionDate BETWEEN :start AND :end")
Page<AssetsTransaction> findAllByDates(
@Param("start") Instant start,
@Param("end") Instant end,
Pageable pageable);
Where Transaction.transactionDate is an Instant type.
how I should pass a date from a javascript app?
java spring spring-data-rest
add a comment |
I have a spring-data-rest API and I create a query like so:
@Query("SELECT at FROM Transaction at WHERE at.transactionDate BETWEEN :start AND :end")
Page<AssetsTransaction> findAllByDates(
@Param("start") Instant start,
@Param("end") Instant end,
Pageable pageable);
Where Transaction.transactionDate is an Instant type.
how I should pass a date from a javascript app?
java spring spring-data-rest
add a comment |
I have a spring-data-rest API and I create a query like so:
@Query("SELECT at FROM Transaction at WHERE at.transactionDate BETWEEN :start AND :end")
Page<AssetsTransaction> findAllByDates(
@Param("start") Instant start,
@Param("end") Instant end,
Pageable pageable);
Where Transaction.transactionDate is an Instant type.
how I should pass a date from a javascript app?
java spring spring-data-rest
I have a spring-data-rest API and I create a query like so:
@Query("SELECT at FROM Transaction at WHERE at.transactionDate BETWEEN :start AND :end")
Page<AssetsTransaction> findAllByDates(
@Param("start") Instant start,
@Param("end") Instant end,
Pageable pageable);
Where Transaction.transactionDate is an Instant type.
how I should pass a date from a javascript app?
java spring spring-data-rest
java spring spring-data-rest
edited Nov 21 '18 at 23:02
Get Off My Lawn
14.2k1783180
14.2k1783180
asked Nov 21 '18 at 22:50
madmauxmadmaux
215
215
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Typically timestamps are stored/transferred/etc. in one of two ways:
UNIX timestamps
This is just a number representing the number of seconds from a fixed time in the past (known as the UNIX epoch).
Java has the Instant#getEpochSecond()
method to obtain this value, and the Instant.ofEpochSecond()
static method to create an Instant
object from a timestamp.
Javascript has the Date
type which can be instantiated from a timestamp (new Date(timestamp * 1000)
), and transformed into a timestamp with difficulty.
ISO 8601 strings
This is just regular ASCII text with a standardised format, for example:
2018-11-21T22:25:58+00:00
You gain the advantage of timezone support with this method.
Java uses Instant#toString()
to get an ISO 8601 string, and this slightly more verbose method to convert back:
Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(string));
Javascript does not have native support for timezones, but it can still produce an ISO-compliant string with Date#toISOString()
and parse it back with the static Date.parse()
.
Whichever way you go, you may wish to use an additional library on the javascript side to gain more control over your timestamps, if this is important to you.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421530%2fhow-to-pass-an-instant-from-a-javascript-app-to-a-spring-data-rest-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Typically timestamps are stored/transferred/etc. in one of two ways:
UNIX timestamps
This is just a number representing the number of seconds from a fixed time in the past (known as the UNIX epoch).
Java has the Instant#getEpochSecond()
method to obtain this value, and the Instant.ofEpochSecond()
static method to create an Instant
object from a timestamp.
Javascript has the Date
type which can be instantiated from a timestamp (new Date(timestamp * 1000)
), and transformed into a timestamp with difficulty.
ISO 8601 strings
This is just regular ASCII text with a standardised format, for example:
2018-11-21T22:25:58+00:00
You gain the advantage of timezone support with this method.
Java uses Instant#toString()
to get an ISO 8601 string, and this slightly more verbose method to convert back:
Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(string));
Javascript does not have native support for timezones, but it can still produce an ISO-compliant string with Date#toISOString()
and parse it back with the static Date.parse()
.
Whichever way you go, you may wish to use an additional library on the javascript side to gain more control over your timestamps, if this is important to you.
add a comment |
Typically timestamps are stored/transferred/etc. in one of two ways:
UNIX timestamps
This is just a number representing the number of seconds from a fixed time in the past (known as the UNIX epoch).
Java has the Instant#getEpochSecond()
method to obtain this value, and the Instant.ofEpochSecond()
static method to create an Instant
object from a timestamp.
Javascript has the Date
type which can be instantiated from a timestamp (new Date(timestamp * 1000)
), and transformed into a timestamp with difficulty.
ISO 8601 strings
This is just regular ASCII text with a standardised format, for example:
2018-11-21T22:25:58+00:00
You gain the advantage of timezone support with this method.
Java uses Instant#toString()
to get an ISO 8601 string, and this slightly more verbose method to convert back:
Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(string));
Javascript does not have native support for timezones, but it can still produce an ISO-compliant string with Date#toISOString()
and parse it back with the static Date.parse()
.
Whichever way you go, you may wish to use an additional library on the javascript side to gain more control over your timestamps, if this is important to you.
add a comment |
Typically timestamps are stored/transferred/etc. in one of two ways:
UNIX timestamps
This is just a number representing the number of seconds from a fixed time in the past (known as the UNIX epoch).
Java has the Instant#getEpochSecond()
method to obtain this value, and the Instant.ofEpochSecond()
static method to create an Instant
object from a timestamp.
Javascript has the Date
type which can be instantiated from a timestamp (new Date(timestamp * 1000)
), and transformed into a timestamp with difficulty.
ISO 8601 strings
This is just regular ASCII text with a standardised format, for example:
2018-11-21T22:25:58+00:00
You gain the advantage of timezone support with this method.
Java uses Instant#toString()
to get an ISO 8601 string, and this slightly more verbose method to convert back:
Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(string));
Javascript does not have native support for timezones, but it can still produce an ISO-compliant string with Date#toISOString()
and parse it back with the static Date.parse()
.
Whichever way you go, you may wish to use an additional library on the javascript side to gain more control over your timestamps, if this is important to you.
Typically timestamps are stored/transferred/etc. in one of two ways:
UNIX timestamps
This is just a number representing the number of seconds from a fixed time in the past (known as the UNIX epoch).
Java has the Instant#getEpochSecond()
method to obtain this value, and the Instant.ofEpochSecond()
static method to create an Instant
object from a timestamp.
Javascript has the Date
type which can be instantiated from a timestamp (new Date(timestamp * 1000)
), and transformed into a timestamp with difficulty.
ISO 8601 strings
This is just regular ASCII text with a standardised format, for example:
2018-11-21T22:25:58+00:00
You gain the advantage of timezone support with this method.
Java uses Instant#toString()
to get an ISO 8601 string, and this slightly more verbose method to convert back:
Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(string));
Javascript does not have native support for timezones, but it can still produce an ISO-compliant string with Date#toISOString()
and parse it back with the static Date.parse()
.
Whichever way you go, you may wish to use an additional library on the javascript side to gain more control over your timestamps, if this is important to you.
answered Nov 21 '18 at 23:22
MTCosterMTCoster
3,83922141
3,83922141
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421530%2fhow-to-pass-an-instant-from-a-javascript-app-to-a-spring-data-rest-api%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown