JS Date格式化为yyyy-MM-dd类字符串

news/2024/7/23 8:35:55 标签: js

原文:https://blog.csdn.net/csdnluolei/article/details/84307668

方法一

Date.prototype.format = function(format)
{
 var o = {
 "M+" : this.getMonth()+1, //month
 "d+" : this.getDate(),    //day
 "h+" : this.getHours(),   //hour
 "m+" : this.getMinutes(), //minute
 "s+" : this.getSeconds(), //second
 "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
 "S" : this.getMilliseconds() //millisecond
 }
 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
 (this.getFullYear()+"").substr(4 - RegExp.$1.length));
 for(var k in o)if(new RegExp("("+ k +")").test(format))
 format = format.replace(RegExp.$1,
 RegExp.$1.length==1 ? o[k] :
 ("00"+ o[k]).substr((""+ o[k]).length));
 return format;
}
 
//日期格式化
var d = new Date();
var useDate = d.format('yyyy-MM-dd');
var useDate2 = d.format('yyyy-MM-dd hh:mm:ss');

方法二

  var Dates = new Date();
  var Y = Dates.getFullYear();
  var M = Dates.getMonth() + 1;
  var D = Dates.getDate();
  var times = Y + (M < 10 ? "-0" : "-") + M + (D < 10 ? "-0" : "-") + D;
  alert(times);

http://www.niftyadmin.cn/n/1691431.html

相关文章

pytorch知识一tensor数据声明、类型转换。微调rensnet34的注意点。

1、tensor类型的数据声明&#xff1a; A、 import torch import numpy as np from torch.autograd import Variable running_corrects 0.0 # 声明一个单一变量3&#xff0c;Tensor默认的tensor类型是(torch.FloaTensor)的简称 atorch.Tensor([3]) aatorch.Tensor(0) # 其中t…

Pgadmin4转圈圈无法进入到界面(pgadmin v4一直卡在loading页面)

原文&#xff1a;https://blog.csdn.net/qna17/article/details/110469846 解决方法&#xff1a; 1、打开Registry Editor&#xff0c;点击进入开始菜单&#xff0c;然后输入【regedit】&#xff0c;点击进入上方的【注册表编辑器】 然后就进入注册表编辑器了&#xff0c;如图…

使用Navicat新建PostgreSQL数据库报错ERROR: new collation (en_ US.utf8) is incompatible with the collation of t

原文&#xff1a;https://www.cnblogs.com/nesnilnehc/p/12448265.html 报错如下&#xff1a; 解决方法&#xff1a; 使用 TEMPLATE 指定创建数据库的模板数据库 -- LC_COLLATE&#xff1a;string sort order -- LC_CTYPE&#xff1a;character classification -- database_…

pytorch里optimizer作用、自动求导autograd,from_numpy、numpy()等函数声明变量时候的浅拷贝、显卡内存 out of memory

1、其中optimizer的作用&#xff0c;其主要起到的作用就是进行权重的更新&#xff0c;如下&#xff1a; netmodels.resnet50(pretrainedFalse) learning_rate0.01 # 权重更新 如果使用自带的optimizer函数进行梯度更新&#xff0c;效率更好&#xff0c;因为其还可以引入梯度 #…

git 常用指令、重获得远程所有的分支、本地分支关联远程分支并且在本地添加远程仓库。代码的pull融合、解决冲突,ignore生效条件,把别人仓库代码提交到自己,新仓库。打tag版本、upstream

1、查看本地git add ./指令后查看暂缓区里的文件内容&#xff08;如果没进行commit操作&#xff0c;这个add会把新旧文件一起放到暂缓区&#xff0c;如果在add后本地删除了某个文件&#xff0c;再进行add&#xff0c;其暂缓区会保留有这个文件的(这个暂缓区是放到.git文件夹下的…

ES6中常用的10个新特性讲解

https://www.jianshu.com/p/ac1787f6c50f https://www.dazhuanlan.com/2020/03/12/5e696e2c65b28/ https://www.manongdao.com/article-856730.html

使用CuDNN进行卷积操作的知识点

参考博客&#xff1a;使用CuDNN进行卷积运算

FaceNet的一些网络训练评估

1、其中主要的损失triplet loss 原理 triplet loss代码如下&#xff1a; def triplet_loss(anchor, positive, negative, alpha):"""Calculate the triplet loss according to the FaceNet paperArgs:anchor: the embeddings for the anchor images.positive:…