-2

Different Browser and OS shows different date format on client side.

In Chrome: dd/mm/yyyy In Safari: yyyy-mm-dd

<input data-drupal-selector="edit-field-date-end-value-date" title="Date (e.g. 2019-05-15)" type="date" min="1969-05-15" max="2069-05-15" data-drupal-date-format="Y-m-d" id="edit-field-date-end-value-date" name="field_date[end_value][date]" value="2019-05-11" size="12" class="form-date hasDatepicker">

Issue with Input type Date, because it is showing as per browsers HTML5 or HTML4.

How to solve this issue? So while load or if select from datepicker then it also solves?

May be need to use Moment JS?

http://jsfiddle.net/g7mvaosL/

-1

Actually the thing is type = date is not supported by safari browser and moreover best practice is to use server time rather using js. May be following code helps

var dateSTR = "2019-05-15";

var date = new Date(dateSTR.replace(/-/g,"/"));

console.log("0:"+ new Date("2019-05-15"))
console.log("1:"+date)
date.setUTCHours(date.getHours());
console.log("2:"+date)
date.setUTCMinutes(date.getMinutes());
console.log("3:"+date);
console.log("4:"+date.toLocaleDateString()); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.