How to format time in yaml in symfony
I'm using symfony 1.4 doctrine. I have an output in my database/browser that looks something like this:
Start time: 12:00:00 End time: 05:00:00
Now I want to change this format like this:
Start time: 12:00 pm End time: 5:00 pm
I tried to convert this in yaml in the backend application like this:
apps/backend/modules/reservation/config/generator.yaml
//some yaml code
fields:
startime: { date_format: h:i A }
endtime: { date_format: h:i A }
I use this format but it did'nt work, probably I set in the schema.yml their data types in "time" f开发者_运维知识库ormat:
reservation/config/doctrine/schema.yml
//some yaml code
columns:
startime: { type: time, notnull: true }
endtime: { type: time, notnull: true }
I set my startime and endtime to time format just to get the time value only for my project. I did'nt set it to date type because it will affect my front end application. For example if I input 5:00
the display will be 12:00 am
, its because I use date type.
To turn this 5:00:00 to 5:00 pm/am in display, I set it into time data type and I use this syntax like this which I used in showSuccess and Indexsuccess template.
<?php echo date('g:i A', strtotime($reservation_application->getStartime()));
this code will format 00:00:00 into 12:00 am or something. but it doesnt change (00:00:00) in the data base. ONLY in display.
Is there a way to format this 00:00:00 into 12 hr format in the yaml file? Many thanks
When you save a time, it's always stored without any culture information. (And as soon as you're going to create a multilingual website, you'll be glad of that!).
That said, it's best to use the DateHelper when formatting dates in the view. This has a format_date
function. When you're using this function, don't forget to set the default_culture
in the settings.yml
(or set the correct culture in the sfUser
).
For example format_date($date, 't');
prints the current time, in the users culture.
For an overview of which patterns you can use, see this page.
精彩评论