为返回的变量添加时间戳
Timestamp a Variable being returned
当
涉及到jQuery时,我有点慢,因为我试图在这种语言中获得一些立足点。我目前正在使用FaceAPI,并且它运行得很好。在识别阶段,我有一个返回信息数组的 Ajax 调用。
$.ajax({
url: 'http://api.face.com/faces/recognize.json?&uids=all&namespace=camera_app&detector=Aggressive&',
data: formdata,
cache: false,
contentType: false,
processData: false,
dataType:"json",
type: 'POST',
success: function (data) {
photo = data.photos[0];
handleResult(photo)
},
但我最感兴趣的是被称为API的"UID",它将一个人的脸与他们的UID相匹配。我想知道的是,一旦返回 UID,是否可以放置时间戳并将其保存到我已设置的数据库中?[旁注:用户照片仅提交到 API,我不将它们保存在我的数据库中。我唯一保存的是用户的名字/姓氏和 UID。我只是不知道时间戳函数如何与返回变量一起工作。
我希望能够在以后提取返回该信息时匹配的 UID 和时间戳。
更新:
以下是向用户显示 UID 和准确性(置信度)的位置:
function handleResult(photo) {
console.log(photo)
var s = "<h2 class='results'>Account Information:</h2>";
if(photo.tags.length) {
var tag = photo.tags[0].uids[0];
s += "<p>";
//$('#result') .html ('Welcome Back:' + photo.uid + ',' + 'Confidence:' + photo.confidence);
if(tag.uid) s += "<li> User:" + tag.uid + "</li>";
if(tag.uid) s += "<li> Accuracy:" + tag.confidence + "%" + "</li>";
if(tag.uid == 0) s += "I got something, but the data wasn't clear. Sorry.";
} else {
s += "<p>Sorry, I didn't find any faces.</p>";
}
$("#result").html(s);
在这个阶段,我希望创建一个时间戳。
解决:
function handleResult(photo) {
console.log(photo)
var s = "<h2 class='results'>Account Information:</h2>";
var month = new Date().getMonth() + 1;
var day = new Date().getDate();
var hours = new Date().getHours();
var min = new Date().getMinutes();
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (min < 10)
min = "0" + min
if(photo.tags.length) {
var tag = photo.tags[0].uids[0];
s += "<p>";
//$('#result') .html ('Welcome Back:' + photo.uid + ',' + 'Confidence:' + photo.confidence);
if(tag.uid) s += "<li> User:" + tag.uid + "</li>";
if(tag.uid) s += "<li> Accuracy:" + tag.confidence + "%" + "</li>";
if(tag.uid) s += "<li> Timestamp:" + month + "/" + day + " " + hours + ":" + min + suffix + "</li>";
if(tag.uid == 0) s += "I got something, but the data wasn't clear. Sorry.";
} else {
s += "<p>Sorry, I didn't find any faces.</p>";
}
$("#result").html(s);
您可以使用
Date 函数在handleResult
回调中创建时间戳。
var timestamp = Math.round( new Date().getTime() / 1000 )
相关文章:
- 如何每10.6秒从时间戳增加+1
- 使用AngularJS从时间戳中获取工作日
- 向 Firebase “push” 方法添加时间戳
- 在javascript中向本地时间戳添加时间戳偏移量
- 将多个csv文件中的时间戳数据添加到highchart中
- 如何将时间戳注释添加到我的输出文件中
- 使用Gulp向文件名添加时间戳
- 为返回的变量添加时间戳
- 如何为城市添加时间戳
- 添加自动增量或时间戳 - JavaScript,jstorage
- 将时间戳添加到已编译的 JavaScript 中
- 如何在firebase中更新字典,同时用angularjs添加时间戳
- 通过添加时间戳清除图像缓存
- 如何在NodeJs或javascript中添加24小时当前unix时间戳
- 添加时间戳到CSS id
- 将时间戳格式添加到折线图x轴
- 使用javascript将时间戳添加到iframe中的src(防止缓存)
- 以编程方式添加时间戳
- javascript php为多个单元格添加时间戳
- 如何在上传文件时为文件名添加时间戳