linkpay-api
Version:
LinkPay JS/TS API SDK
34 lines (33 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.genYYYYMMDDThhmmsshh00 = exports.genUUIDWithoutDash = void 0;
var crypto_1 = require("crypto");
/**
* Generate UUID without dash, you can use this method to generate like MsgID
*
* @returns UUID without dash
*/
function genUUIDWithoutDash() {
var uuid = (0, crypto_1.randomUUID)();
var msgID = uuid.replace(/-/g, '').substring(0, 32);
return msgID;
}
exports.genUUIDWithoutDash = genUUIDWithoutDash;
/**
* The format is YYYY-MM-DDThh:mm:ss+hh:00. Such as 2020-03-04T15:39:40+08:00.
*
* @returns current date time string with specific format
*/
function genYYYYMMDDThhmmsshh00() {
var date = new Date();
var year = date.getFullYear();
var month = ("0".concat(date.getMonth() + 1)).slice(-2);
var day = ("0".concat(date.getDate())).slice(-2);
var hours = ("0".concat(date.getHours())).slice(-2);
var minutes = ("0".concat(date.getMinutes())).slice(-2);
var seconds = ("0".concat(date.getSeconds())).slice(-2);
var offset = ("0".concat(date.getTimezoneOffset() / -60)).slice(-2);
var formattedDate = "".concat(year, "-").concat(month, "-").concat(day, "T").concat(hours, ":").concat(minutes, ":").concat(seconds, "+").concat(offset, ":00");
return formattedDate;
}
exports.genYYYYMMDDThhmmsshh00 = genYYYYMMDDThhmmsshh00;