如何在Couchdb查看图中的当地时间或时区格式或获得日期减少?

发布于 2025-02-04 11:15:14 字数 148 浏览 3 评论 0原文

我在couchdb中有一个数据库,该数据库是一个字段类型的日期时间,但是当我在查看(地图)中显示数据时,数据显示以ISO格式显示。我想在LocalTime中显示如何格式化?我尝试了两个函数,但不使用JavaScript函数tostring()或TolocalString()不起作用

I have a database in couchDB, a field type datetime, but when i show in view (map) the data show in format ISO. I want to show in localtime, how to format? i tried with two function but not work with javascript function toString() or toLocalString() not work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哭了丶谁疼 2025-02-11 11:15:14

我在搜索和搜索后发布了对我有用的答案,我为您提供了一个完整的示例地图中的视图,以及如何将日期从标准格式转换为本地格式。在这种情况下,我使用-6是中美洲时区。

function(doc){
    if(doc.entrada!==null){
        var d = new Date(doc.entrada);
        d.setTime(d.getTime() - 6 * 60 * 60 * 1000);      
        var[mes,dia,anho]= d.toLocaleString().split(',')[0].split('/');      
        emit([anho,mes.padStart(2,'0'),dia.padStart(2,'0'),doc.idEmpleado], d.toLocaleString());
}

将VAR DateTime从字段DateTime

var d=new Date(doc.entrada);

更改为UTC-6。

d.setTime(d.getTime() - 6 * 60 * 60 * 1000); 

如果将Time-4更改为UTC-4,

d.setTime(d.getTime() - 4 * 60 * 60 * 1000); 

我 ()要转换为字符串,它将显示在您在服务器上配置的区域 /时间中显示,然后这是一件要分开的事情,并且完成了。
我希望它对您有用并为您提供帮助。

I publish the answer that worked for me after searching and searching, I leave you a complete example of the view in map reduce and how I convert the date from standard format to local format. In this case I use -6 which is the Central American time zone.

function(doc){
    if(doc.entrada!==null){
        var d = new Date(doc.entrada);
        d.setTime(d.getTime() - 6 * 60 * 60 * 1000);      
        var[mes,dia,anho]= d.toLocaleString().split(',')[0].split('/');      
        emit([anho,mes.padStart(2,'0'),dia.padStart(2,'0'),doc.idEmpleado], d.toLocaleString());
}

I declare var datetime from field datetime

var d=new Date(doc.entrada);

change time-zone to UTC-6

d.setTime(d.getTime() - 6 * 60 * 60 * 1000); 

if change time-zone to UTC-4

d.setTime(d.getTime() - 4 * 60 * 60 * 1000); 

So I managed to change the format of the date for the view in couchdb, you can use the javascript functions toLocalString() toString() to convert to a string, it will be displayed in the zone / time that you have configured on the server, then it is a thing to do split and you're done.
I hope it works for you and helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文