我在这里看到了一个潜在的答案,但那是YYYY-MM-DD:JavaScript日期验证
我为MM-DD-YYYY修改了上面的代码,但我还是无法让它工作:
String.prototype.isValidDate = function()
{
var IsoDateRe = new RegExp("^([0-9]{2})-([0-9]{2})-([0-9]{4})$");
var matches = IsoDateRe.exec(this);
if (!matches) return false;
var composedDate = new Date(matches[3], (matches[1] - 1), matches[2]);
return ((composedDate.getMonth() == (matches[1] - 1)) &&
(composedDate.getDate() == matches[2]) &&
(composedDate.getFullYear() == matches[3]));
}
Run Code Online (Sandbox Code Playgroud)
如何让上述代码适用于MM-DD-YYYY,更好的是MM/DD/YYYY?
谢谢.
我最近一直在努力学习嵌入式系统编程.volatile在声明变量时,我观察到关键字限定符的使用率相当高?
volatile在嵌入式系统编程中声明变量时有什么意义?
基本上应该使用关键词.我确实读过有关编译器优化和关键字使用的内容.还有与内存映射寄存器有关的东西.
例如,我读了这篇StackOverflow帖子,但我不明白它是如何在嵌入式环境中应用的.更具体地说,我不明白何时应该使用关键词.我确实读过有关编译器优化和关键字使用的内容.还有一些与内存映射寄存器相关的东西,但我不明白何时使用它.
我想从mongo db获取整个通知列表,但是它返回empty([])数组,我也知道我需要回调或更短的方法。您是否有想法通过node.js从mongodb收集任何数据?如果我调用此/ Notify方法(http://127.0.0.1:5000/Notify)
var MongoClient = require('mongodb').MongoClient;
var express = require("express");
var app = express();
format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/Test', function (err, db) {
if (err) {
throw err;
} else {
console.log("successfully connected to the database");
}
db.close();
});
app.get('/Notifies', function (req, res) {
// BAD! Creates a new connection pool for every request
console.log('connected');
MongoClient.connect('mongodb://127.0.0.1:27017/Test', function (err, db) {
if (err) throw err;
var coll = db.collection('Notifies');
var arr = [];
coll.find({}, function (err, docs) {
docs.each(function …Run Code Online (Sandbox Code Playgroud)