Hey everyone!
I’m trying to figure out how to set 12h time format. I tried to add to the System settings doctype format as h:mm a, but no luck. But I still see it in 24h format. How can I change time format for the whole system?
Hey everyone!
I’m trying to figure out how to set 12h time format. I tried to add to the System settings doctype format as h:mm a, but no luck. But I still see it in 24h format. How can I change time format for the whole system?
You can’t set it.
This is weird. Any suggestion how to fix it?
Or at least a ref point where I can dig into it to fix it for everyone?
And I am also curious, why this wasn’t implemented?
Its working for me you can use Client Script
Client Script
frappe.ui.form.on('Employee Checkin', { // Replace with your actual DocType
refresh: function(frm) {
format_datetime_fields(frm);
add_change_listener(frm);
},
onload_post_render: function(frm) {
format_datetime_fields(frm);
add_change_listener(frm);
},
validate: function(frm) {
format_datetime_fields(frm);
}
});
function format_datetime_fields(frm) {
// Specify the datetime field name
var datetime_field_name = 'time'; // Replace with your actual datetime field name
var datetime_value = frm.doc[datetime_field_name];
if (datetime_value) {
var offset = -new Date().getTimezoneOffset();
var offset_hours = Math.floor(offset / 60);
var offset_minutes = offset % 60;
var formatted_offset = (offset_hours >= 0 ? '+' : '-') + ('0' + Math.abs(offset_hours)).slice(-2) + ':' + ('0' + Math.abs(offset_minutes)).slice(-2);
var formatted_datetime = moment(datetime_value).utcOffset(formatted_offset).format('DD-MM-YYYY hh:mm:ss A');
frm.fields_dict[datetime_field_name].$input.val(formatted_datetime);
}
}
function add_change_listener(frm) {
var datetime_field_name = 'time'; // Replace with your actual datetime field name
frm.fields_dict[datetime_field_name].$input.on('blur change', function() {
format_datetime_fields(frm);
});
}