I'm using Date::i18nFormat to display dates using the desired locale.
This is an example: $post->date->i18nFormat("dd 'of' MMMM"). This Outputs: 19 of june.
I would like to capitalize the first letter of the month, so it would output instead: 19 of June.
is it possible?
Thank you
Related
I have a LocalDateTime object and I would like to format this, to have printouts like:
Tue 23. Nov. Therefore, I used a DateTimeFormatter like:
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("e dd. LLL")
But unfortunately I get Tue 23. 11 The month is a number and no letters!?
The correct format pattern string is E dd. MMM. Excuse my Java syntax.
private static final DateTimeFormatter DATE_FORMATTER
= DateTimeFormatter.ofPattern("E dd. MMM", Locale.ENGLISH);
Also remember to specify desired locale for your formatter.
Trying it out:
LocalDate date = LocalDate.of(2021, Month.NOVEMBER, 23);
String formatted = date.format(DATE_FORMATTER);
System.out.println(formatted);
Output is the desired:
Tue 23. Nov
Spelling out how my format pattern is different:
I am using upper case E for the abbreviation of the day of week. Lower case e should give you the number of the day of week like 2 for Tuesday. eee should work for the abbreviation too.
I am using MMM for the abbreviation of the month. LLL is for the standalone form. Some languages use a different form of the month depending on whether the day of month is present or not. A language may for example use the nominative for the month alone and the genetive with a day number, a bit the differene between November and of November. Since you have the day included, you should not use pattern letter L here. Funnily for some languages that have not got a stand-alone form (like English), Java gives you the number instead when you specify LLL.
Edit: you asked:
How would that look for "November" fully written out? "MMM" works for
"Dec."
The documentation that you linked to in another comment gives the answer:
Text: The text style is determined based on the number of pattern letters used. Less than 4 pattern letters will use the short form.
Exactly 4 pattern letters will use the full form. …
So use MMMM instead of MMM:
private static final DateTimeFormatter DATE_FORMATTER
= DateTimeFormatter.ofPattern("E dd. MMMM", Locale.ENGLISH);
Tue 23. November
Documentation link: DateTimeFormatter
I have the two fields
November 14 2019 10:35:24 AM and November 14 2019 as string from file
I want to convert in datstage to these fields as
11/14/2019 10:35:24AM and 20191114 respectively
Please note: after month there is one space between November and 14 and two spaces between 14 and 2019
and in output 11/14/2019 and time there is two spaces
As the input is a string and it seems you want again a string as a result string manipulation functions in a Transformer stage are always an option.
Alternatively you could also try to use the String_to_Timestamp and STRING_TO_DATE function on the same page
You will find valid format options here
In talend
Oct 21 - Oct 27 (2019)
is there any way to convert above text to date format, I only want 21 oct 2019 as 21/10/2019 format
Yes, it is not simple, as you have two dates on one field only, with Year appearing only once.
You can achieve this with tMap_1 --> tNormalize --> tMap_2
In tMap_1 you will have to separate "MMM-dd" from "YYYY", which appears at the end of your string. Use split method on your input field :
myFlow.myDateField.split("\\(")[0] will give you the part with `Oct 21 - Oct 27`
myFlow.myDateField.split("\\(")[1] will give you the part with the year.
Use StringHandling.LEFT to get the year only, without the closing parenthesis.
Use StringHandling.TRIM to get rid of extra spaces.
Then you will have two fields in the output.
You can then use tNormalize (normalize on "-") to put the year in front of every MMM/dd field.
In the output you'll have two rows and two columns :
"Oct 21|2019"
"Oct 27|2019"
In the final tMap , concatenate your two input fields as you wish, and use TalendDate.parseDateLocale to parse your date. (TalendDate.parseDate won't work as you have "Oct", which requires parseDateLocale method to work).
need some suggestions on below requirement.
Each response help a lot thanks in advance....
I have a date of type String with timestamp ex: Jan 8 2019 4:44 AM
My requirement is if the date is single digit I want date to be 1 space and digit
(ex: 8) and if the date is 2 digits which is dates from 10 to 31 I want date with no space(ex:10) and also same for hour in timestamp.
to summarize: if the date is 1 to 9 and hour in timestamp is 1 to 9 looking for below string
Jan 8 2019 4:44 AM
if the date is 10 to 31 and hour in timestamp is 10 to 12 looking for below string
Jan 18 2019 12:44 AM
right now I am creating a date in following way:
val sdf = new SimpleDateFormat("MMM d yyyy h:mm a")
but the above format satisfies only one condition which is dates from 1 to 9.
my application is spark with scala so looking for some spark scala code or java.
I appreciate your help...
Thanks..
java.time
Use p as a pad modifier in the format pattern string. In Java syntax (sorry):
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
"MMM ppd ppppu pph:mm a", Locale.ENGLISH);
System.out.println(LocalDateTime.of(2019, Month.JANUARY, 8, 4, 44)
.format(formatter));
System.out.println(LocalDateTime.of(2019, Month.JANUARY, 18, 0, 44)
.format(formatter));
Jan 8 2019 4:44 AM
Jan 18 2019 12:44 AM
And do yourself the favour: Forget everything about the SimpleDateFormat class. It is notoriously troublesome and fortunately long outdated. Use java.time, the modern Java date and time API.
Link: Oracle tutorial: Date Time explaining how to use java.time.
To quote the DateTimeFormatter class documentation:
Pad modifier: Modifies the pattern that immediately follows to be padded with spaces. The pad width is determined by the number of pattern letters. This is the same as calling DateTimeFormatterBuilder.padNext(int).
For example, 'ppH' outputs the hour-of-day padded on the left with spaces to a width of 2.
I am trying to get the current week number with Zend Framework.
In France, weeks are defined like this :
A week begins on Monday (whereas weeks begin on Sunday in the US).
The first week of the year is the week which contains the 4th of January.
In 2014, the first week begins January 1st. But if I use in Zend Framework 1.12 for this date like $zend_date->get(Zend_Date::WEEK) it returns 53 (and not 1). and for January 12th, it returns 1 (and not 2)
How can I correct that ? I already tried to change the locale to fr-fr but it didn't work.
Regards
Tried to replicate your problem doing
$date1 = new Zend_Date('2014-01-01');
$date2 = new Zend_Date('2014-01-12');
$date1->get(Zend_Date::WEEK) // gives 01
$date2->get(Zend_Date::WEEK) // gives 02
Also tried passing 'fr' as locale. It gives the correct answer.
I am not sure if it's a Zend issue.
Try the PHP solution:
php > echo date('W',strtotime('2014-01-01'));
01
php > echo date('W',strtotime('2014-01-12'));
02