相关疑难解决方法(0)

将毫秒转换为日期(jQuery/JavaScript)

我有点像漫步者,但我会尽力保持清晰 -

我很无聊,所以我正在制作一个"shoutbox",我对一件事感到有些困惑.我希望得到一条消息输入的时间,我想确保我得到服务器时间,或者至少确保我没有得到用户的本地时间.我知道这没关系,因为除了我之外,任何人都不会使用这个东西,但我想要彻底.我环顾四周并测试了一些东西,我认为这样做的唯一方法就是获得自?/?/ 1970之后的毫秒或其他任何东西,因为对每个人来说都是一样的.

我这样做是这样的:

var time = new Date();
var time = time.getTime();
Run Code Online (Sandbox Code Playgroud)

这会返回一个数字1294862756114.

有没有办法转换1294862756114为更具可读性的日期,比如DD/MM/YYYY HH:MM:SS

所以,基本上,我正在寻找JavaScript相当于PHP的date();功能.

javascript jquery datetime

184
推荐指数
7
解决办法
36万
查看次数

如何将 Angular 中的日期保存为 Firestore 的时间戳?

我正在尝试将具有出生日期和激活日期的人的个人信息保存到 Angular 的 Firestore 数据库中;

但是,传递带有Date()类型字段的对象,日期将保存为字符串:

this.treatment.activationDate = new Date();
// gives such result in firestore with string type
// activationDate: "2018-11-16T09:48:51.137Z"
Run Code Online (Sandbox Code Playgroud)

还尝试使用服务器时间戳,但以下方法未返回有效值:

firebase.firestore.FieldValue.serverTimestamp()
Run Code Online (Sandbox Code Playgroud)

结果在 Firestore(不允许上传图片抱歉:)):

activationDate: (map)
     _methodName: FieldValue.serverTimestamp 
Run Code Online (Sandbox Code Playgroud)

但是,此方法无法为我提供自定义日期的时间戳(例如birthDate) 那么使用angular 在firestore 中将日期保存为时间戳对象的最佳方法是什么?

.....
import  * as firebase from 'firebase';
.....
export class AddPatientComponent implements OnInit { 
......

this.treatment.activationDate = new Date();
  //firebase.firestore.FieldValue.serverTimestamp();
  console.log("timestamp: ", this.treatment.activationDate,                  firebase.firestore.FieldValue.serverTimestamp()); 
  this.patientService.savePatient(this.patient, this.treatment,   this.courseMeds);
Run Code Online (Sandbox Code Playgroud)

还有一个模型:

export class CourseMed{
  amountPerDay: number;
  atc: String;
  name: String;
  days: number;
  dosage: number;
  form: …
Run Code Online (Sandbox Code Playgroud)

javascript firebase angularfire2 angular google-cloud-firestore

5
推荐指数
1
解决办法
6951
查看次数