moment timezone display the wrong offset [duplicate] - momentjs

This question already has answers here:
Momentjs format moment object and keep offset
(1 answer)
Momentjs changes the timezone value
(3 answers)
Closed 4 months ago.
The following code return the wrong offset
const date = moment("2022-03-26 00:00:00 +0600",
"YYYY-MM-DD HH:mm:ss ZZ");
const res = date.format("YYYY-MM-DD HH:mm:ss ZZ");
console.log(res);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
The result is 2022-03-25 21:00:00 +0300
see https://codesandbox.io/embed/admiring-mopsa-054yvv?fontsize=14&hidenavigation=1&theme=dark
if I add date.utcOffset("+0600") after the date init than it solves the problem
but than I need to add an extra step to extract the offset
Is there a way to tell moment to use the offset from the original date string?

Related

SSRS Report Date Formate using X++ [duplicate]

This question already has answers here:
Axapta: Convert utcDateTime to date
(3 answers)
Closed 3 months ago.
please help me. I am doing MS Dynamics D365 Report laypot. I have a date that I want to set for a specific formate - YYYY/MM/DD. I can get that formate but I have the time in the end. I just want date formate to be YYYY/MM/DD only with out time at the end. I am using DateTimeUtill to string for converting the date, since the date is a datetime formate in MS Dynamics D365 system. How can I convert the date to YYYY/MM/DD??. As I want a single ine code that can converted. Please help. Thanks
report layout having YYYY/MM/DD + time
Here is my code:
PurchPurchaseOrderHeader.Notes += "Rev " + int2Str(counterforrevisiondate)
+ ": " + DateTimeUtil::toStr(vendPurchOrderJour.PurchOrderDate) + "\n";
I am expecting the date to have datetime formate of YYYY/MM/DD without the time in the end. But it did not expect that way.
strFmt("%1", DateTimeUtil::date(vendPurchOrderJour.PurchOrderDate)) ?

Convert time in string to datetime.datetime [duplicate]

This question already has answers here:
How do I parse an ISO 8601-formatted date?
(29 answers)
Closed 8 months ago.
I have a time in the form time = '2022-06-29 07:55:28' that has the type str I want to store it in the firebase in the firebase's format. For that I have tried datetime.strptime(time, '%Y %m %d %I:%M:%S%p'). But I am getting the following error:
ValueError: time data '2022-06-29 07:55:28' does not match format '%Y %m %d %I:%M:%S%p'
Kindly help me out in this. Should I go for momentjs or something similar?
I was entering the wrong format. It should have been
time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
Note: We have to enter the format according to the format of the data given!

How can I extract just YYYY-MM-DD from the retrieved variable? [duplicate]

This question already has an answer here:
How to get substring in the given string from Robot Framework?
(1 answer)
Closed 12 months ago.
If I have:
${time} = OperatingSystem.Get Modified Time #{Files}[${i}]
${onlyDate} = ???
How can I easily just get the YYYY-MM-DD from ${time} instead of YYYY-MM-DD HH:MM:SS?
you can try this with DateTime Library :
${date} = Convert Date ${date} result_format=%Y-m%-d%
Refer more at - https://robotframework.org/robotframework/latest/libraries/DateTime.html#Date%20formats

How to convert the UTC date into local date in Moment.js?

I have a date in this format "2020-12-16T02:48:00" that came from the server. How can I convert this into local date and time? I tried some code but couldn't succeed.
Below is the attempt that I had made in angular after receiving date from the server.
response.data.map(date=>{
var centralDate = moment( date).zone("-06:00");
date = moment(centralDate).local().format('YYYY-MM-DD hh:mm:ss');
})
If indeed the value is in UTC (as per the title of your question), and it looks like "2020-12-16T02:48:00", and you want to convert it to local time, then you should do the following:
moment.utc(date).local().format('YYYY-MM-DD HH:mm:ss');
That does the following:
Parses the input in terms of UTC
Converts it to local time
Formats it as a string in the given format
Note also that you had hh in your original format. That is for hours in a 12-hour time format and thus you shouldn't use it without also using either A or a to indicate AM/PM or am/pm. Otherwise HH is for hours in a 24-hour time format.
If your issue is that the timezone doesn't change you can resolve using utcOffset (https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/) in this way:
response.data.map(date=>{
date = moment( date).utcOffset(-360);
})
Where 360 is the conversion fo the hours in minutes
var d= new Date();
d = new Date(d+ "Z")
I am not an expert in angular but I guess the trouble in your date is the word “T”. May be using string removal function you can remove the word “T” and then it becomes a proper date time value?

Convert String to timestamp in Sparklyr [duplicate]

This question already has an answer here:
changing the JVM timezone in sparklyr
(1 answer)
Closed 3 years ago.
I'd like to convert String to time stamp, I used the below code but it added 4 hours to the timestamp, I really appreciate if you could help me to figure it out the issue
I used Sparklyr.
fds<- fds %>%
mutate(time2 = from_unixtime(
unix_timestamp(transaction_time, "yyyy-MM-ddHH:mm:ss"), "yyyy-MM-dd HH:mm:ss"))
fds<- fds %>% mutate(transaction_time_2 = to_timestamp(time2))
transaction_time is string with this format '2018-05-3016:00:40'
by using from_unixtime, it has been converted to ''2018-05-30 16:00:40' and by using to_timestamp it has been converted to 2018-05-30 20:00:40. everything is correct except 20 hour, I still expected 16.
I encountered the same problem, I think it relates to the timezone settings
try the following at the top of your program, then the problem should disappear:
sparklyr::invoke_static(sc, "java.util.TimeZone", "getTimeZone", "GMT") %>%
sparklyr::invoke_static(sc, "java.util.TimeZone", "setDefault", .)
check out this answer for more details :
changing the JVM timezone in sparklyr

Resources