简体   繁体   English

从解析Android SDK更新带有服务器时间的日期字段?

[英]Updating a date field with server time from parse android sdk?

I am using Parse back-end, and i have a Date field which i need to fill with Server time. 我正在使用Parse后端,并且我有一个Date字段,我需要用服务器时间填充。 But i am updating this from Android-SDK and i want to update it with server time. 但是我正在从Android-SDK更新它,我想用服务器时间更新它。 (I don't want to take local time from mobile and convert as it is not reliable, may be if the user's time was wrong) (我不希望从移动设备获取本地时间并进行转换,因为它不可靠,可能是因为用户的时间不正确)

You can use beforeSave cloud method hook for such scenarios. 您可以在这种情况下使用beforeSave云方法挂钩

Parse.Cloud.beforeSave("YourClassName", function(request, response) {
   request.object.set("yourDateField", new Date());
   response.success();
});

This will set "yourDateField" with the server time stamp (GMT) before inserting the row into the Class. 在将行插入类之前,这将使用服务器时间戳(GMT)设置“ yourDateField”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM