📅  最后修改于: 2023-12-03 15:21:22.743000             🧑  作者: Mango
YYMMDDHHmmss (Year-Month-Day-Hour-Minute-Second) is a date time format that is widely used in programming. This format is very useful for sorting, parsing, and storing date and time data in an efficient way.
The YYMMDDHHmmss format follows a specific syntax that is:
YYMMDDHHmmss
where:
The YYMMDDHHmmss format can be used for a variety of purposes in programming, such as:
import datetime
# get current date time in YYMMDDHHmmss format
current_time = datetime.datetime.now().strftime('%y%m%d%H%M%S')
print(current_time)
# output: 210728122306
# convert YYMMDDHHmmss string to datetime object
dt_object = datetime.datetime.strptime('210728122306', '%y%m%d%H%M%S')
print(dt_object)
# output: 2021-07-28 12:23:06
// get current date time in YYMMDDHHmmss format
const current_time = new Date().toISOString().replace(/[-:.TZ]/g, '').slice(2, 14);
console.log(current_time);
// output: 210728123003
// convert YYMMDDHHmmss string to date object
const date_string = '210728123003';
const year = parseInt('20' + date_string.slice(0, 2));
const month = parseInt(date_string.slice(2, 4)) - 1;
const day = parseInt(date_string.slice(4, 6));
const hour = parseInt(date_string.slice(6, 8));
const minute = parseInt(date_string.slice(8, 10));
const second = parseInt(date_string.slice(10, 12));
const date_obj = new Date(year, month, day, hour, minute, second);
console.log(date_obj);
// output: Wed Jul 28 2021 12:30:03 GMT+0800 (GMT+08:00)
YYMMDDHHmmss is a concise and standardized date time format that can be easily used in various programming applications. It offers an efficient way to store, sort, parse, and display date and time data.