Format now mm/dd/yyyy hh:mm AMPM


JavaScript • JQuery


	var d = new Date();
	formattedDate = d.toLocaleDateString('en-US', {
		month: '2-digit',
		day: '2-digit',
		year: 'numeric',
	}).replace(/\//g, '/');
	var formattedTime = d.toLocaleTimeString('en-US', {
		hour: '2-digit',
		minute: '2-digit',
  		hour12: true,
	});	
	$('#field').val(formattedDate + ' ' + formattedTime);

Written by fbrefere001

Posted by fbrefere001 on Friday October 18, 2024