Python
# coding=utf-8 import time import sys def func(): # Formatted output time s1 = int(("%Y%m%d%H%M%S", ())) # Timestamps, which need to be converted to milliseconds for output as the default is seconds s2 = int(round(() * 1000)) return s1, s2 def once(): '''Run once if no command line arguments are specified''' s1, s2 = func() print(s1) print(s2) def main(): args = # Get command line arguments if len(args) > 1: count = args[1] # Command line argument is a number, generate the specified number of timestamps if () and int(count) > 1: s1, s2 = func() # Tuple deconstruction # Increment time as many times as specified in the parameter for i in range(int(count)): print(s1 + i) print(s2 + i) else: once() else: once() if __name__ == "__main__": main()
Generate as many times as specified, executed on the command line, the following command is specified to generate 10
python 10
This code can only be run using the NodeJS environment, which needs to be installed first.
function func() { const dt = new Date(); // Array in order of year, month, day, hour, minute, and second const source = [(), () + 1, (), (), (), ()]; let t = source[0]; // The first digit is the year, and the time digits are spliced in starting with the month; months, days, hours, etc., if they are one-digit numbers, they are filled with zeros to ensure that they are displayed as two-digit numbers for (let i = 1; i < ; i++) { const element = source[i]; t = t * 100 + element; } // Static method for Date object to get the timestamp directly return [t, ()]; // Returns an array, the first with the year, month, day, hour, minute, and second numbers, and the second with a timestamp } /* Run once if no command line arguments are specified */ function once() { const [s1, s2] = func(); (s1); (s2); } // Getting command line arguments in NodeJS() // To run in a normal JS environment (e.g. a browser), you need to remove the handling of this special variable (). const args = ; if ( > 2) { const len = Number(args[2]); if (!isNaN(len) && len > 1) { let [s1, s2] = func(); // Array Deconstruction // Generate multiple timestamps as many times as specified by the command line argument, incrementally for (let i = 0; i < len; i++) { (s1 + i); (s2 + i); } } else { once(); } } else { once(); }
Generate as many times as specified, executed on the command line, the following command is specified to generate 10
node 10
Feel free to leave a comment in the comments section to share your thoughts together if you make it to the end or if it helps you.
Above is the details of python and generate current timestamp example, more information about python and generate current timestamp please pay attention to my other related articles!