I have a string with a full date like this: "2016/03/05 13:47:18 +0000".
I want covert it to "2016-03-05" or "05-March-2016" on Angular scope. I also have integer time duration = 421471 which I want to convert to a time format like "23:45" or "1 hour , 50 minute".
{{sound.created_at | date}}
{{sound.duration}}
How can I do that?
To solve your issue please use momentjs as very famous lib to deal everything about date in js.
To make it work well with Angularjs/4, please have a look here.
Related
I want to convert Date into String format. First I want to get Date from react-datePicker and only want to convert it into single String UTC to String format "22-10-2020"
On your onChange event, you can get e.target.value and use like it new Date(e.target.value).toISOString().split('T')
if you want to convert the Date into string format then use toLocaleDateString() with the date i.e new Date().toLocaleDateString(); // 26-11-2020. <- string
You can Do This Things with use of Moment
, You can Easyly switch you format and also play with date and time type. Moment js is Easy Way to play with such thing .
Currently I am using angularjs in my project in which i am converting a date format '2019-05-09T20:09:11.677Z' using angular js to 'MM/dd/yyyy' but its giving me wrong output '05/10/2019'. Expected Output is '05/09/2019'.
What is the issue? Can anybody help me.
{{'2019-05-09T20:09:11.677Z' | date:'MM/dd/yyyy'}}
Current Output (Wrong): 05/10/2019
Expected Output (Right) : 05/09/2019
Date filter considers your timezone. Since the date you're trying to print has 8pm as time, I guess you're in a timezone in the range +0400 and +1200, making the date falling into 05/10/2019.
If you want to force the timezone to something different, e.g. UTC, you can use
{{ '2019-05-09T20:09:11.677Z' | date:'MM/dd/yyyy' : '+0000' }}
You have to specify timezone as one of parameters.
{{ date_expression | date : format : timezone}}
eg:
{{date| date:'shortDate':'GMT' }}
For more Information AngularJs
Small demo for your help Demo
I use momentjs inside angular js and I acount the duration in seconds and I can format it in HH:mm format as 03:35 but I cannot find in documentaion and google to how show it in format 3h 35m could anybody point me to right documentation???
This should get what you're after:
moment().format("H[h] mm[m]");
Take a look at Format from the momement.js docs. The [] is used to escape characters in format strings.
I'm mixing MVC Data Annotations and AngularJs validations ng-pattern.
What I've done so far is this thing:
[RegularExpression("/^[0-9]{4}-[0-9]{2}-[0-9]{2} 20|21|22|23|([0-1][0-9]):[0-5][0-9]:[0-5][0-9]$/", ErrorMessage = "Date format: yyyy-mm-dd hh:mm:ss")]
As you can see, I try to format date: yyyy-mm-dd hh:mm:ss.
I want to make it 24 hours time.
My problem is that form is getting valid when I type:
2015-21 , 2015-22 // 2015-20 is not valid, cannot understand why
2015-12-20 21 // I want user to enter minutes and seconds, because it also has datetimepicker, which is more useful and it sets format as I want
So, why my regular expression is not working as I expect?
Your regex does not work as expected because you did not use a ^ anchor (although I guess this expression is anchored, but still it is better to play it safe) and you did not enclose the alternatives into a group, and thus 21, 22, 23 are valid values.
Here is a fixed expression:
^[0-9]{4}-[0-9]{2}-[0-9]{2} (?:20|21|22|23|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$
^^^ ^^
See demo
change your regex instead to be like this
^[0-9]{4}-[0-9]{2}-[0-9]{2} ((20|21|22|23)|([0-1][0-9])):[0-5][0-9]:[0-5][0-9]$
check this Demo
I only changed 20|21|22|23|([0-1][0-9]) in your regex to ((20|21|22|23)|([0-1][0-9]))
I'm using the CakeTime class for my localization of dates & times.
For dates it works like I want it to:
$timestring = $this->Time->format('Y-m-d H:i:s', time());
echo 'DateTime: '.$this->Time->i18nFormat($timestring);
// Result => DateTime: 11/08/2013
I want it to also display the time.
For example in the US they use AM/PM and in other places they use the 24 hour notation.
I've looked but can't seem to find a way to do this.
Any idea's?
Edit*
To be clear, the localization works perfectly for the dates(have the LC_TIME files), but the i18nFormat function only returns the date, and from what i saw, passing a format will use that format, not the localized one, example MM/DD/YYYY vs DD.MM.YYYY in a different locale
*Edit2:
The solution vicocamacho gave in the comments is the correct one
So to get the Date + Time in the localized form:
$this->Time->i18nFormat(time(), '%x %X') does the trick!
You can use the TimeHelper::i18nFormat method. You also can check this repo to find common date/time translations https://github.com/cakephp/localized be sure to store them in the APP/locale/<locale>/LC_TIMEdirectory