Get 12 hour time from Time Helper in CakePHP - cakephp

I'm using the niceShort function in the Time Helper in Cake to display some times from my database. It works wonderfully, but it would be great to be able to have niceShort use 12 hour time instead of 24. Is there a way to do this without modifying the helper?

To make a 12-hour time, simply do this in your view:
<?php echo $time->format('g:la', $string); ?>
For a list of all of the different formatting options, see:
http://php.net/manual/en/function.date.php
In other words, my above example (g:la) would output 4:45pm

I still wanted to be able to use the nice and niceShort functions, so I modified the Time helper and moved it into app/views/helpers.
.

Use the format function and provide the date/time format you want. It is the same format string as the date function in PHP.

As cakephp's format() uses PHP's strftime() formatting options. You can use
%I:%M %p or %r
echo $this->Time->format($news['News']['modified'],'%d/%m/%Y %I:%M %p');
it will format for example: 21:34:17 to 09:34:17 PM. You can read more here.

Related

AngularJS convert string date and integer time

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.

Regular Expression date time using MVC Data Annotations

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]))

Adding new date formats to ExtJS

Ext.Date contains formats a and A for am/pm or AM/PM, respectively.
I want to add a format, call it b, for a/p without the m. I have searched parseFunctions and formatFunctions but did not find where the old format is defined.
Can anyone shed some light on this matter?
Have a look at formatCodes in Ext.Date:
The base format-code to formatting-function hashmap used by the format
method. Formatting functions are strings (or functions which return
strings) which will return the appropriate value when evaluated in the
context of the Date object from which the format method is called. Add
to / override these mappings for custom date formatting.

Getting date value from Excel to Sendkeys() Method

How to get Date Value from Excel cell to Sendkeys() method if I use object as a variable? An error occuring at sendkeys like Charsequence[].
object x=sheet.getRow(8).getCell(1).getStringCellValue();
wd.findElement(By.id("MyMember_DateOfBirth")).sendKeys(x);
The method takes a charSquence/String, I'll assume that you get the content from the Sheet as a String reading the index or cell value.
Here is the Javadoc link might help
http://selenium.googlecode.com/git/docs/api/java/index.html
void sendKeys(java.lang.CharSequence... keysToSend)
Hope this helps
never worked a lot on apache poi, but going through the api I would suggest you to take the date value in cell through
Date d=sheet.getRow(8).getCell(1).getDateCellValue();
Later you can use SimpleDateFormat class to get your date in string format.
or else you can use DataFormatter class in poi and use formatCellValue method for your usage.
Hope it helps.

CakePHP: CakeTime i18nFormat for date and time

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

Resources