0

Is there a way to specify your own date pattern besides the included ones (small, medium, full). The main point here is that it should work with i18n. I've tried a couple of things but I couldn't get it to work...

Yii::app()->dateFormatter->format("l d/m/Y",$slide->date_start);

I know about strftime but the problem here is that different hosting providers use different locale string... and you have to customize it...

I'm looking for an elegant way of doing this.

I'd like to display the date in l d/m/Y form...

Update: Never mind... I've just found out that dateFormatter doesn't use standard php date format...

2 Answers 2

1

I think you should measure time solely in Unix Time because Timezones & date formats are a presentation-layer problem. Unix time is always UTC & It's a single number, so easier to pass around in code.

As far the problem of "hosting providers use different locale string", just ask the user his timezone & display according to that. far less error-prone than trying to guess.

For date formatting, have a look at YII's format()

Hope it answers your question

Sign up to request clarification or add additional context in comments.

1 Comment

As i've said in my update the correct format is EEEE, d/M/yyyy which is a little bit different than in standard php...
0

Here's a related yii forum discussion

The yii forum solution worked for me to avoid raw SQL NOW() statements but still produce database-friendly date strings with PHP date() and time() functions which otherwise return integers.

In protected/config/main.php:

...
'params'=>array(
    'mysqlDateTimeFormat' => 'Y-m-d H:i:s', # ':u' adds microsecond precision,
...

Then, wherever you want to put a date-time string into a model field use

$myModel->myDate = date(Yii::app()->params['mysqlDateTimeFormat']);

Obviously you can enter the date/time format into the date (or time) functions directly if you prefer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.