How to parse a date from string (template needed) - ruby

I have a string like 2015-07-09T12:00:00+00:00. How can I parse it using Date.strptime()? Help me to build a template.

Try using DateTime.strptime instead of Date.strptime, since you're using time and timezone.

Related

Transform a string into ISO datetime format | Freemarker

So I get the date and time which is, for example, 17.11.2021 and 12:44. Now I want to convert this date and time into the formate which Freemarker is using (yyyy-MM-dd hh:dd:mm:ss). However the problem here is that I can't convert it properly. I tried like:
${myDateTime?datetime.iso?string("yyyy-MM-dd HH:mm:ss")}
But this wont work. I always get an error message. Can anyone explain or show me the correct formation in this case ?
Assuming myDateTime is a String (and not already a Date object), and it looks like 17.11.2021 12:44, you can convert it to ISO format like this:
${myDateTime?datetime("dd.MM.yyyy HH:mm")?string.iso}
Above myDateTime?datetime("dd.MM.yyyy HH:mm") converts the string to a Date (which is a format-independent representation), and then ?string.iso formats the Date with ISO format.
Note that it would be much cleaner if myDateTime was a Date, not a String. Then you just do this: ${myDateTime?string.iso}

Format currency with dot instead of comma using i18n

We are using java.text.NumberFormat class to format the currency values using the method getInstance(Locale paramLocale). Our issue is when we pass es_CO(Columbia) language code it automatically formats it in value 123,00 instead of 123.00. Is there a way to format with dot instead of comma?
I am using Spring platform(hybris)
Please note due to business reasons it is not possible for me to change the locale.
You can use DecimalFormat to have your own format.
Look at this How can I format a String number to have commas and round?

In Apache NiFi, how do I print current date in ISO format with timezone

I am using the now() function to add a dynamic attribute to the flow. The value that's assigned to the attribute is human-readable format. I would like to get the value in the ISO format:
2019-09-21T12:00:00Z
I have tried this expression:
${now():format("yyyy-MM-ddTHH:mm:ss.SSS'Z'")}
However, I am getting an error on 'T'.
ERROR: failed to process session due to Illegal pattern character 'T';
Is there a quick way to format the date using the EL?
I am NiFi version 1.9.1
Thanks
According to the documentation,
${now():format("yyyy-MM-dd'T'HH:mm:ss'Z'", "GMT")}
will give your expected result.

How to convert current date format(YYYY-MM-DD HH:MM:SS) to (YYMMDD) format in freemarker language

I have used code ${.now?iso("UTC")} to get the current date and time stamp inside the freemarker templates, but I would like to convert the current date format (YYYY-MM-DD HH:MM:SS) to (YYMMDD) format. Please provide your suggestion.
At the moment (2.3.28) ?string doesn't support forcing UTC. So if the time_zone FreeMarker configuration setting is not UTC, you can do this:
<#setting time_zone="UTC">
${.now?string('yyyyMMdd')}
However, then the further dates will also use UTC. If that's a problem then either you use a custom date format (which is a date format implemented in custom Java code, so it can do anything; see: https://freemarker.apache.org/docs/pgui_config_custom_formats.html#pgui_config_custom_formats_ex_cust_algo_date), or use this hack:
${.now?date?iso('UTC')?replace('-', '')}

What's the correct date format to turn this string into a date?

I'm consuming a JSON API, which returns dates, such as the following: 2012-11-13T17:32Z. What's the correct value for a formatString for an associated NSDateFormatter instance?
Edit:
I tried #"yyyy-MM-dd'T'hh':'mm'Z'".
You don't need the quotes around the colon, and you should be using capital H's for the hours.

Resources