conversion of Date : issue in IE - date

I have a date in following format..
"Tue Jun 21 10:52:32 +0000 2016"
Whenever i am trying to convert this date in
new Date("Tue Jun 21 10:52:32 +0000 2016") it is giving me an error says invalid date and i also tried moment("Tue Jun 21 10:52:32 +0000 2016") and moment(new Date("Tue Jun 21 10:52:32 +0000 2016")) it is giving the same error as invalid date in IE.
This issue is only in IE, in chrome it is working fine. I want the result in this format moment("Tue Jun 21 10:52:32 +0000 2016").format("dddd, MMMM Do YYYY, h:mm:ss a")
Please help me, Thanks in advance.

Don't use the Date object for its parsing abilities. You will find the implementations vary considerably across browsers. You're already using moment.js, so use its parser instead. You will have to be explicit about the input format.
var m = moment("Tue Jun 21 10:52:32 +0000 2016", "ddd MMM D H:mm:ss ZZ YYYY");
You can then format it however you like by passing a different format to the format function.
Also note that by default, moment will convert the above to the user's local time zone. If that's not what you intended, then consider using moment.parseZone instead. Refer to the user guide, and also to this blog article.

Related

Transform string format whith month into timestamp in datastage

I want transform the string
Thu, 21 Jan 2021 09:48:38 +0100
in timestamp format "%yyyy-%mm-%dd %hh.%nn.%ss.6"
how to do?
Thank you
Check out the StringToTimestamp function and the other type conversion functions in DataStage.
You could also work with string manipulation first.
Note that you have not provided the information about the fraction of the second yet.

Flutter parse GMT

Hello,I have a question!
I want to parse Time, GMT to Milliseconds。
for example:Thu, 10 Oct 2019 02:05:09 GMT.
I try DateTime.parse("Thu, 10 Oct 2019 02:05:09 GMT")
i get this error
Exception caught by widgets library The following FormatException was
thrown building GroupPage(dirty, state: _GroupPage#cb39c): invalid
date format Thu, 10 oct 2019 02:05:09 GMT
You can use the HttpDate class to parse this.
Example:
DateTime parsedDate = HttpDate.parse("Thu, 10 Oct 2019 02:05:09 GMT");
DateTime.parse can parse only ISO 8601 dates, not an arbitrary ones. From docs:
The function parses a subset of ISO 8601 which includes the subset
accepted by RFC 3339.
Examples of accepted strings:
"2012-02-27 13:27:00"
"2012-02-27 13:27:00.123456z"
"2012-02-27 13:27:00,123456z"
"20120227 13:27:00"
"20120227T132700"
"20120227"
"+20120227"
"2012-02-27T14Z"
"2012-02-27T14+00:00"
"-123450101 00:00:00 Z": in the year -12345.
"2002-02-27T14:00:00-0500": Same as "2002-02-27T19:00:00Z"
DateTime.parse method is not an option for your date string, unless you get it in ISO 8601 format.
The intl package can parse relatively flexible dates and times: https://pub.dev/packages/intl#date-formatting-and-parsing

How to convert from Mon Sep 02 17:00:00 PDT 2019 to 09022019 in groovy?

I'm getting date format "Mon Sep 02 17:00:00 PDT 2019" from UI to process. But i want to convert as 09022019. Below code i tried but that convert to one day before.
sampleDate = Mon Sep 02 17:00:00 PDT 2019
sdf = new SimpleDateFormat("MMddyyyy")
sdf.format(sampleDate)
I'm getting 09012019 but expected date is 09022019.
Please help.
Assuming you're on Java 8+ and Groovy 2.5+, you can use the Java 8 Date/Time APIs:
import java.time.*
new Date("Mon Sep 02 17:00:00 PDT 2019").toZonedDateTime().format('MMddyyy')
You need add setTimeZone for SimpleDateFormat.
By default, SimpleDateFormat uses default timezone of system if none specified. It can be checked just by changing second line of you code to sdf = new SimpleDateFormat("MMddyyyy z"). Perhaps it's why you getting 09012019.
One more thing. TimeZone.getTimeZone("PDT") do not return timezone object for PDT. I guess because PDT is not a time zone but a pseudo-time zone. Then we will use something like TimeZone.getTimeZone("America/Los_Angeles").
sdf = new SimpleDateFormat("MMddyyyy")
sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"))
sdf.format(sampleDate)
Will return 09022019 no matter of system timezone.

How to get RFC1123 Date format for current date time using XSLT 2.0

I am trying to retrieve current date time in RFC1123 date format in XSLT.
has anybody tried this using XSL2.0?
I have seen code for converting various date times based on zone in XSLT2.0 and to format in specific date time format such yyyy/mm/dd or YYYY:MM:DDTHH:MM:SS.0Z, but couldnt find a way to format it to show like this
Tue, 09 Jul 2019 20:34:29 GMT
concat(date:add('1970-01-01T00:00:00',concat('PT',floor(dp:time-value() div 1000),'S')),':',dp:time-value() mod 1000)
This returns in GMT format like this 2019-07-09T21:01:26:547
How to format it for - Tue, 09 Jul 2019 20:34:29 GMT using XSLT2.0?
Use current-dateTime() to get the current date and time and then use format-dateTime to format it as needed, see the spec https://www.w3.org/TR/xslt20/#function-format-dateTime on details: a picture string
'[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]'
on my machine in German summer time gives
format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')
as
Wed, 10 July 12:01:13 GMT+02:00
This is meant as an example on the use of format-dateTime, I haven't checked the exact details of the RFC you cited to try to implement the exact requirements.
Thanks for quick reply, your solution worked using Altova XML Spy, but unfortunately it didnt worked for me in Datapower using XSLT2.0, Not sure what was wrong, may be some issue with DP firmware version.
just for other users to make this post more helpful. I tried below 2 options which didnt work for me, but might be useful for others.
using XSLT
<xsl:value-of select="java:java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC))"></xsl:value-of>
<xsl:value-of select="format-dateTime(current-dateTime(), '[FNn,*-3], [D01] [MNn] [H01]:[m01]:[s01] [z]')"/>
So I used Gateway script to get same date format which I was looking for and stored in context variable using below
var dateNeeded = new Date()).toUTCString(); //Thu, 11 Jul 2019 21:08:12 GMT

How to convert dates of this kind to month-day-year format?

I have to convert the following date format to m-d-Y format. How can I achieve it?
$date='Thu, 20 Jun 2013 09:09:52 UTC' and what I am suppose to pass in query is 6-20-2013
Please let me know a few quick tricks.
Thanks
date('m-d-Y', strtotime('Thu, 20 Jun 2013 09:09:52 UTC'))