Datetime widget example

- Main Page
- Related Pages
- Data Structures
- Files
- Examples

Datetime widget example

This code places three Elementary Datetime widgets on a window, each of them exemplifying the widget's different usage.

The first of them is "only Date display":

//datetime showing only DATE
datetime = elm_datetime_add(bx);
evas_object_size_hint_weight_set(datetime, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(datetime, EVAS_HINT_FILL, 0.5);
elm_datetime_field_visible_set(datetime, ELM_DATETIME_HOUR, EINA_FALSE);
elm_datetime_field_visible_set(datetime, ELM_DATETIME_MINUTE, EINA_FALSE);
elm_datetime_field_visible_set(datetime, ELM_DATETIME_AMPM, EINA_FALSE);
elm_box_pack_end(bx, datetime);
evas_object_show(datetime);

For "only Time display", see the second datetime:

//datetime showing only TIME
datetime = elm_datetime_add(bx);
evas_object_size_hint_weight_set(datetime, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(datetime, EVAS_HINT_FILL, 0.5);
elm_datetime_field_visible_set(datetime, ELM_DATETIME_YEAR, EINA_FALSE);
elm_datetime_field_visible_set(datetime, ELM_DATETIME_MONTH, EINA_FALSE);
elm_datetime_field_visible_set(datetime, ELM_DATETIME_DATE, EINA_FALSE);
elm_box_pack_end(bx, datetime);
evas_object_show(datetime);

The third one will display datetime shows both Date and Time, corresponding format will be taken from system locale. Note, besides, that the strings are different for different language settings.

Datetime format can be programmatically set by using elm_datetime_format_set():

//datetime showing both DATE and TIME
datetime = elm_datetime_add(bx);
evas_object_size_hint_weight_set(datetime, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(datetime, EVAS_HINT_FILL, 0.5);
elm_box_pack_end(bx, datetime);
evas_object_show(datetime);
The default format of any locale consists:

- Year Field
- Month Field
- Date Field
- Hour Field(12hr/24hr format)
- Minute Field
- AM/PM (if exists).

This is how the example program's window looks like with the datetime widget showing only date, only time and both date & time:

See the full source code for this example.