xxxxxxxxxx
function atTime(callback, time) {
// use regex for extract information of time
const regex = /^(?:(\d{1,2}):)?(\d{1,2})(?::(\d{1,2}))?(?:\s+(\d{1,2})\/(\d{1,2})\/(\d{4}))?$/;
const matches = time.match(regex);
if (!matches) {
console.error("the format of time/date is unknow");
return;
}
// getting diferant propriety of time
const [, hours, minutes, seconds, day, month, year] = matches;
const date = new Date();
if (hours) date.setHours(hours);
if (minutes) date.setMinutes(minutes);
if (seconds) date.setSeconds(seconds);
if (day) date.setDate(day);
if (month) date.setMonth(month - 1); // important month start at 0
if (year) date.setFullYear(year);
const now = Date.now();
const delay = date.getTime() - now;
}
is possible to call atTime with
'13:46'
'13:46:00'
'08/01 13:46'
'08/01/2022 13:46'
'08/01/2022 13:46:00'
'08-01 13:46'
'08-01-2022 13:46'
'08-01-2022 13:46:00'
and other
xxxxxxxxxx
String dtStart = "2010-10-15T09:27:37Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
Date date = format.parse(dtStart);
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
xxxxxxxxxx
print(DateTime.parse('2020-01-02')); // 2020-01-02 00:00:00.000
print(DateTime.parse('20200102')); // 2020-01-02 00:00:00.000
print(DateTime.parse('-12345-03-04')); // -12345-03-04 00:00:00.000
print(DateTime.parse('2020-01-02 07')); // 2020-01-02 07:00:00.000
print(DateTime.parse('2020-01-02T07')); // 2020-01-02 07:00:00.000
print(DateTime.parse('2020-01-02T07:12')); // 2020-01-02 07:12:00.000
print(DateTime.parse('2020-01-02T07:12:50')); // 2020-01-02 07:12:50.000
print(DateTime.parse('2020-01-02T07:12:50Z')); // 2020-01-02 07:12:50.000Z
print(DateTime.parse('2020-01-02T07:12:50+07')); // 2020-01-02 00:12:50.000Z
print(DateTime.parse('2020-01-02T07:12:50+0700')); // 2020-01-02 00:12:50.00
print(DateTime.parse('2020-01-02T07:12:50+07:00')); // 2020-01-02 00:12:50.00
xxxxxxxxxx
String string = "January 2, 2010";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH);
LocalDate date = LocalDate.parse(string, formatter);
System.out.println(date); // 2010-01-02
xxxxxxxxxx
var mydate = new Date('18/07/2022 11:09');
console.log(mydate.toDateString());
Run code snippetHide results
xxxxxxxxxx
function stringToDate(_date,_format,_delimiter)
{
if(_date != ''){
var formatLowerCase=_format.toLowerCase();
var formatItems=formatLowerCase.split(_delimiter);
var dateItems=_date.split(_delimiter);
var monthIndex=formatItems.indexOf("mm");
var dayIndex=formatItems.indexOf("dd");
var yearIndex=formatItems.indexOf("yyyy");
var month=parseInt(dateItems[monthIndex]);
month-=1;
var formattedDate = new Date(dateItems[yearIndex],month,dateItems[dayIndex]);
if(formattedDate == 'Invalid Date') formattedDate = undefined;
return formattedDate;
}else{
return undefined;
}
}
xxxxxxxxxx
=ARRAYFORMULA(IFERROR(IFERROR(REGEXREPLACE(A2:A,
"(\d+)/(\d+)/(\d{2,4})", "$2/$1/$3")*1, A2:A)*1, A2:A))