I've got a date string from my database which has this format:
Tue Nov 12 2013 18:14:46 GMT+0100 (CET)
I want to convert it into a ISOString and im currently doing that with:
var iso = new Date(val.text_date).toISOString();
However for some reason the output time is moved 1 hour backwards?
This is the output im getting:
2013-11-12T17:14:46.000Z
How can i avoid this?
Short answer: the time is converted into UTC, and your original time was displayed in UTC+1, hence the one hour difference.
The Date.toISOString() method converts the date into a string in the ISO 8601 format. Note that the returned date in your example ends by a Z: 2013-11-12T17:14:46.000Z. As per the Mozilla documentation and Wikipedia:
If the time is in UTC, add a Z directly after the time without a
space. Z is the zone designator for the zero UTC offset
Related
I was trying to convert a timezone from CST to UTC inside a data flow. A quick google gave me that CST is in UTC-6:00, so it should add 6 hours.
The following derived column function for some reason only added 5 hours:
toUTC(localDatetime, 'CST')
Moreover, CurrentUTC('CST') Gave me the correct 6 hours difference, so I had to rewrite this function like this:
LocalDatetime + hours(toInteger((currentUTC('CST') - currentUTC()) / 1000 / 60 / 60))
// Minus between timestamps gives difference in milliseconds
Is this intended behavior? I am worried that when the timezone "shifts" this code will break, so using toUTC would be the best solution, but for some reason it gives incorrect results now
toUTC() converts a datetime to UTC time zone based on the Daylight-Saving Time effectiveness.
When you are converting from CST to UCT, if your date falls when Daylight saving is effective, then it adds +5 to your date else adds +6 to your date.
Example:
Derived column expression: toUTC(toTimestamp(Date_UTC), 'CST')
I have to convert utc time to ist time in my excel the the time format is 10:00:00 utc this has to converted in IST timing.
Please suggested
There are no inbuilt functions that identify/convert the timezones. We can extend the capabilities of Excel Time() function to solve this use case.
=A1+Time(5,30,0)
For IST, you will have to add 5 hours and 30 minutes. Similarly, you can convert to any timezone by adding/subtracting the time difference.
The three inputs given to the Time() are hours,minutes and seconds.
This function returns the timestamp in a serial number format. Excel will interpret this number and show the timestamp in a readable format.
During my scripting in Vugen (Web/HTTP-HTML), I have captured the time in date format (Thu 31 Oct 2019 10:08:29) in parameter file using date-time format (%a %d %b %Y %H:%M:%S). The value I have to pass in the Body section of web_custom_request, it accepts only milliseconds (1572516509000). How we can convert this date format to milliseconds in LR.
Can anyone suggest to me here?
Thanks,
Soumen
Help to understand the use case. Do you need to have the time in milliseconds at the time of submission? At some time in the past for a given date and time? At some point in the future for a given date and time?
The reason why I ask is that there are built in functions for generating a UNIX styled timestamp for the current time. You could potentially plus or minus some number of milliseconds off of this for dates in the past or future depending upon the nature of the request: 86,400,000 milliseconds in a day
I'm trying to add/subtract days from moment time object. However, the problem im having is that the time offset is different then the local time of the server.
in db my time
2019-08-14T21:38:50-04:00
however, locally I get +0000
moment().format('YYYY-MM-DD hh:mm ZZ')
2019-08-15 07:19 +0000
so now if I try to convert the time stored in the db
moment("2019-08-14T21:38:50-04:00").format('YYYY-MM-DD hh:mm ZZ')
2019-08-15 01:38 +0000
if I use parseZone() I get
moment.parseZone("2019-08-14T21:38:50-04:00").format('YYYY-MM-DD hh:mm ZZ')
2019-08-14 09:38 -0400
I also tried manually removing the offset of 4 hours (to balance it out?)
moment("2019-08-14T21:38:50-04:00").utcOffset(-240).format('YYYY-MM-DD hh:mm ZZ')
2019-08-14 09:38 -0400
But the value out (after formatting) is always different then in.
How do I get 2019-08-14T21:38:50-04:00 as the output after I format moment obj back to a string?
moment.parseZone("2019-08-14T21:38:50-04:00").format()
or
moment.parseZone("2019-08-14T21:38:50-04:00").format(moment.ISO_8601())
or
moment.parseZone("2019-08-14T21:38:50-04:00").format("YYYY-MM-DD[T]HH:mm:ssZ")
All of the above will produce "2019-08-14T21:38:50-04:00", the same as the input string.
The main problem in your third attempt is that you were using hh (12-hour clock) instead of HH (24-hour clock).
I've been searching all over and just can't find a explanation or reason why this is happening but the parse(String) method of DateFormat just isn't parsing my String correctly.
I'm trying to parse a String into the date format that is used for HTTP headers and got as far as getting the String on its own such as:
Thu, 11 Nov 2010 18:34:22 GMT
Which is in the format:
E, d MMM yyyy HH:mm:ss z
But when I use df.parse(dateStr); this is what I get out of it:
Thu Nov 11 18:34:22 GMT 2010
Which is nothing like what I wanted, why is the year now after the GMT? Why is there no comma anymore? And why is the date after the month?
I'm completely confused about this now and can't find a solution but I really need the date to be in that format. Is the comma messing things up? or the colons?
Thanks for your time,
Infinitifizz
P.S.
Forgot to mention this but I've tried dateformat.setLenient(false) and it makes no difference.
P.P.S
I'm trying to do this to compare the dates with date1.before(date2) and after() etc to see if one is newer than the other but I can't do this because the parsing isn't working.
Even though they look the same but just the format is different, they are not the same because after calling getTime() on both of them (When I have provided 2 identical dates) the longs are not the same. As in the date is:
Thu, 11 Nov 2010 19:38:52 GMT for a lastModified() on a File
If I input the String "Thu, 11 Nov 2010 19:38:52 GMT" and then compare their longs once converting the string to a date using parse() and then calling getTime() on that date I get:
lastModified = 1289504332671
fromString = 1289504332000
It is only the last 3 digits that are different, does this have any significance?
Thanks again for your time and sorry I didn't put this bit in first,
Infinitifizz
The result format is the default format of Date#toString() (click link to see the javadoc). You're apparently doing a System.out.println(date). You would like to use SimpleDateFormat#format() instead with another pattern to format it in the desired format. E.g.
String newDateStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
Update: You shouldn't care about the format when using Date. You should only care about the format at that point when Date is to be converted (displayed) as String. As to the difference in timestamps, the Date uses millisecond precision for the timestamp while HTTP header uses second precision. You'd like to divide the timestamps by 1000 before comparing.