I'm having trouble formatting this date with moment.js
2016-02-23T08:00:00Z
I just want something like moment.format("MM DD YYYY").
This code output 02 23 2016
moment.utc('2016-02-23T08:00:00Z').format('MM DD YYYY')
Related
I need to convert a date format
2020-07-28T21:00:00(RAML date-time only format)
to
Tue, 28 jul 2020 08:49:37 GMT format.
how to achieve this in mule-4?
%dw 2.0
output application/java
---
"2020-07-28T21:00:00" as DateTime
as String {format:"eee, dd MMM yyyy HH:mm:ss"}
https://simpleflatservice.com/mule4/Date_format.html
To format a date it’s necessary to first coerce to a Date format then format it to the desired Date format as did below
%dw 2.0
output application/java
---
"2020-07-28T21:00:00" as DateTime
as String {format:"eee, dd MMM yyyy HH:mm:ss"}
o/p of this will be :
Tue, 28 Jul 2020 21:00:00
here addition to this I would like to say that this is the default GMT format
but if you want to convert any date format for example GMT to IST then you have to do as in the below code
%dw 2.0
output application/java
---
(now() as DateTime >> "IST")
as String {format:"eee, dd MMM yyyy HH:mm:ss"}
in above code at the time when I am answering this question now() is giving the time as
2021-02-03T07:08:37.002Z[GMT] but I want my answer in IST so I changed it first to IST and then in the desired format.
so final o/p of this will be in IST as below:
Wed, 03 Feb 2021 12:42:59
I am trying to convert a Date String of format
Mon Dec 03 2018 05:30:00 GMT+0530 (India Standard Time)
into a format of YYYY-MM-DD so as to use it for a value in input date but it's not able to parse it.
I tried using these formats but it didn't work.
moment(new Date(Mon Dec 03 2018 05:30:00 GMT+0530 (India Standard Time))).format("YYYY-MM-DD")
But since it's not a Date.parse() format, it doesn't work.
Any ideas would be welcome.
You need to pass the dateFormat while creating the moment object, inorder for it to recognize and parse non-default formats.
Try,
var dateFormat = "ddd MMM DD YYYY HH:mm:ss zZZ";
var m = moment("Mon Dec 03 2018 05:30:00 GMT+0530 (India Standard Time)", dateFormat);
m.format("YYYY-MM-DD");
More details for parsing from string: https://momentjs.com/docs/#/parsing/string-format/
Any site around date format days that the conversion needs MMM but this wont work. When i do...
${date_to_search_for}= Convert Date 2017-06-14 13:03:02.506610 date_format=%Y-%M-%d %H:%m:%S.%f result_format=%d %MMM %Y 00:00:00 exclude_millis=True
I get
14 06MM 2017 00:00:00
Obviously am looking for Jun in this example
%MMM is not a valid directive in datetime. You want to use %b if you want a month's abbreviated name. Your result_format should be:
result_format=%d %b %Y 00:00:00
My data set looks like the following:
dsn register_at
1 AC000W000014612 Thu Mar 02 21:34:30 UTC 2017
2 AC000W000016124 Tue Mar 14 19:40:57 UTC 2017
3 AC000W000016219 Tue Apr 14 19:29:10 UTC 2017
I need to get just the month specification like Mar, Apr etc for each dsn. How do I grab only the month specification from the register at variable?
You should perform the following steps:
Set up your locale to English (if your machine's locale is already English, you can skip this step!)
Use the as.Date function to format your data (Please check the format string below)
Once the data is in Date format, just extract the month part from the date.
Sample code:
#Create the data frame
mdata <- data.frame(dsn=character(0), register_at=character(0))
mdata <- edit(mdata)
#Set the locale to en_US (This is required, because month/date names are in english)
Sys.setlocale(category = "LC_TIME", locale="English_US.1252")
Sys.getlocale()
#Convert the variable to date
mdata$register_at_date <- as.Date(mdata$register_at,format="%a %b %d %H:%M:%S UTC %Y")
#Extract the month part
mdata$month <- months(mdata$register_at_date)
#Print out the data frame
print(mdata)
You can use substr function as Month names are always in the same possition.
substr(df$register_at, 5, 7)
For future reference, I would try to get the dates written in a more standardized format, such as year-month-day hours:minutes:seconds.
However, I know that we may not always have control over the format of the data (boo). Just thought I'd mention that, if it was in a more standardized format, the lubridate package has a function called floor_date that would accomplish this easily.
For this specific instance, you could just split the string by a space and select only the second element after that split:
> # create data frame
> # note that, per your question, dsn and register_at are factors
> d <- data.frame(dsn=factor(c("AC000W000014612", "AC000W000016124", "AC000W000016219")),
+ register_at=factor(c("Thu Mar 02 21:34:30 UTC 2017", "Tue Mar 14 19:40:57 UTC 2017", "Tue Apr 14 19:29:10 UTC 2017")))
>
> library(stringr) # load package
> d$register_month <- str_split_fixed(as.character(d$register_at), " ", 3)[,2] # convert to character, split at a space, take the second element
> d
dsn register_at register_month
1 AC000W000014612 Thu Mar 02 21:34:30 UTC 2017 Mar
2 AC000W000016124 Tue Mar 14 19:40:57 UTC 2017 Mar
3 AC000W000016219 Tue Apr 14 19:29:10 UTC 2017 Apr
Note that register_month will be a character vector, so if you want it as a factor, you'd have to also use as.factor to get it back to a factor.
how to get this date format Tue, Apr 29 '14. I need single quote in year, I have tried like this.
string dt = Convert.ToDateTime(row["Date"].ToString()).ToString("ddd, MMM dd ''yy");
You will have to escape the quote using a backslash. To avoid escaping the backslash I have used verbatim string literal (prefixed with #):
#"ddd, MMM dd \'yy"
Try this:
date.ToString("ddd, MMM dd \"'\"yy")