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);
EVAS_HINT_EXPAND
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
EVAS_HINT_FILL
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
EINA_FALSE
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
elm_box_pack_end
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
elm_datetime_add
Evas_Object * elm_datetime_add(Evas_Object *parent)
Adds a new datetime Widget.
Definition: elm_datetime.c:40
elm_datetime_field_visible_set
void elm_datetime_field_visible_set(Evas_Object *obj, Elm_Datetime_Field_Type fieldtype, Eina_Bool visible)
Set a field to be visible or not.
Definition: elm_datetime.c:158
ELM_DATETIME_MINUTE
@ ELM_DATETIME_MINUTE
Indicates Minute field.
Definition: elm_datetime.h:214
ELM_DATETIME_AMPM
@ ELM_DATETIME_AMPM
Indicates AM/PM field .
Definition: elm_datetime.h:215
ELM_DATETIME_HOUR
@ ELM_DATETIME_HOUR
Indicates Hour field.
Definition: elm_datetime.h:213
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
evas_object_size_hint_weight_set
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
evas_object_size_hint_align_set
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650

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);
ELM_DATETIME_MONTH
@ ELM_DATETIME_MONTH
Indicates Month field.
Definition: elm_datetime.h:211
ELM_DATETIME_YEAR
@ ELM_DATETIME_YEAR
Indicates Year field.
Definition: elm_datetime.h:210
ELM_DATETIME_DATE
@ ELM_DATETIME_DATE
Indicates Date field.
Definition: elm_datetime.h:212

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.