123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- export function getTime2() {
- let d = new Date();
- let hours = d.getHours()
- let minutes = d.getMinutes()
- let seconds = d.getSeconds()
- hours = hours > 9 ? hours + '' : '0' + hours
- minutes = minutes > 9 ? minutes + '' : '0' + minutes
- seconds = seconds > 9 ? seconds + '' : '0' + seconds
- return hours + minutes + seconds
- }
- export function getDate2() {
- let d = new Date()
- let year = d.getFullYear()
- let month = d.getMonth() + 1
- let day = d.getDate()
- return year + getFormatDate(month) + getFormatDate(day)
- }
- export function getDate() {
- let d = new Date();
- let year = d.getFullYear();
- let month = d.getMonth() + 1;
- let day = d.getDate();
- return year + '-' + getFormatDate(month) + '-' + getFormatDate(day);
- }
- /**
- * 获取生日
- *
- * @param IDCard
- * @returns {string}
- */
- let getBirthDate = function (idCard) {
- let year = idCard.substring(6, 10);
- let month = idCard.substring(10, 12);
- let day = idCard.substring(12, 14);
- return year + '-' + month + '-' + day;
- }
- /**
- * 获取当前时间
- *
- * @returns {string}
- */
- let getNowDate = function () {
- let d = new Date();
- let year = d.getFullYear();
- let month = d.getMonth() + 1;
- let day = d.getDate();
- return year + '-' + getFormatDate(month) + '-' + getFormatDate(day);
- }
- /**
- * 格式化时间
- *
- * @param value
- * @returns {string}
- */
- let getFormatDate = function (value) {
- if (value === undefined || value === "") {
- return '';
- }
- let str = value;
- if (parseInt(value) < 10) {
- str = '0' + value;
- }
- return str;
- }
- /**
- * 获取年龄
- *
- * @param startDateStr
- * @param endDateStr
- * @returns {number}
- */
- let getAge = function (startDateStr, endDateStr) {
- //计算两个日期相差多少年
- let startDate = new Date(startDateStr);
- let endDate = new Date(endDateStr);
- let yearNum = endDate.getFullYear() - startDate.getFullYear()-1;
- //获取两个日期(月+日)部分
- let sStr = startDateStr.substring(5, 10);
- let eStr = endDateStr.substring(5, 10);
- //判断两个日期大小
- //判断是否过生日
- if (new Date(sStr) <= new Date(eStr)) {
- return yearNum + 1;
- }
- else {
- return yearNum;
- }
- }
- export default {
- getIDCardInfo(idCard) {
- if (idCard.length === 18) {
- //获取计算后出生日期
- let birthDateStr = getBirthDate(idCard);
- //设置出生日期
- // console.log(birthDateStr);
- //获取当前的日期
- var nowDateStr = getNowDate();
- //获取计算后年龄(两个日期之间)
- var age = getAge(birthDateStr, nowDateStr);
- let sex = idCard.substring(16, 17);
- // console.log(sex%2 ===0)
- //设置年龄
- return { birthDateStr: birthDateStr, age: age, sex: sex % 2 === 0 ? '2' : '1' }
- }
- },
- clickNavto: (path, type) => {
- // console.log(path, type)
- if (type == 'redirect') {
- uni.redirectTo({
- url: path
- })
- }
- if (type == 'switchTab') {
- uni.switchTab({
- url: path
- })
- }
- if (type == 'navigateBack') {
- uni.navigateBack({
- delta: 1
- })
- }
- if (!type) {
- uni.navigateTo({
- url: path
- })
- }
- }
- }
|