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
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 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;
}
}