how to use RFC1123 date in http header?
hey guys. can smb explain to me how to use DateTimeFormatter RFC_1123_DATE_TIME? Im making a request to the api and i need to have
Date
header with its value being in RFC1123 format. can smb help me out? i dont understand what to write here:
thanks in advance.36 Replies
β
This post has been reserved for your question.
Hey @bambyzas! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
I mean, it depends on what client API you're using.
In the most general case, there's nothing special, that's like if you wanted to set a numeric header you'd first convert your value to String then set the header to that String. It's the same principle with a date.
Use
ZonedDateTime
to get the current date and time. ZonedDateTime is preferred as it includes the time zone information which is important for the RFC-1123 format.
If they use spring's HttpHeaders, then they can simply do
headers.setDate(now);
It knows to take in a ZonedDateTime and it will format it with RFC_1123_DATE_TIMEoh wow. i can do it in such simple way?
but will it add GMT letters at the end? bc in postman i set my date to
Mon, 27 May 2024 12:55:00 GMT
, so i need the same for my appWell, it depends on whether you'll use spring's internal API for http client.
If you want it to use GMT, you should force the ZonedDateTime to be on GMT. Let me check an example
i use this stuff:
yep, its Spring functionality
yes, but you will not have the added hours:
and with formatted you will have:
ah, i need the first version
but i see that you arent using formattedDate var anywhere for headers. only for sout
so i can ditch it, right?
and i can just use this
yes
But it will show London time zone
where GMT starts
what do u mean?
If you are in some another time zone you ill not see added hours
im gmt +3
crap
me too
so whats the solution then?
ah wait
ok. i see
You just need
GMT
at the end?
but with added hours?
You can edit the formatted string and just add it manuallynope. as i understand i dont need added hours, but i need GMT letters appended. for example now its 10:54 on my computer. but if i want to make a request with postman, i need to have this:
I edited like this:
but u have +0300 before GMT letters. i dont need that
I see
i just need to have current GMT time and add GMT letters to the time
and thats where im stuck
Still you can edit the string yourself and find the +0300 and cut it
and create new string
simple school level string operations
but hours will be added
at your time zone
but wait. i see that this is what i need
and i dont need any string operations
Yes. But I tell you again... - it will give you London time
but thats what i need. i just told you
There:
ffs
nvm
I achieved with added hours to my Lithuanian time.
i sorted it out
man reik GMT laiko, nereik man prisidet triju valandu π
Ok. Just I wanted myself exactly my time. I insisted on this.
Supratau
AΕ‘ pasidariau kaip aΕ‘ noriu.
viskas ok. aciu uz pagalba πͺ
π€
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.