bootstrap-datepicker:如何使用特定时区? [英] bootstrap-datepicker: How to use specific time zone?

查看:151
本文介绍了bootstrap-datepicker:如何使用特定时区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 bootstrap-datepicker 创建了一个小程序来选择日期并将其写入MySQL 。

I created a small program to select the date using bootstrap-datepicker and write it to MySQL.

这个日期必须是欧洲/柏林的本地日期,无论用户目前在哪里。

The catch is that this date must be local to Europe/Berlin regardless where the user is at the moment.

$(....).datepicker({ startDate: 'today' });

我的问题是:如何设置 startDate 在不使用服务器端代码(PHP)或任何其他库的情况下在特定时区本地?

My question is: how do I set startDate to be local to specific timezone without using server side code (PHP) or any other libraries?

我尝试使用时刻 + moment-timezone 但它也显示本地浏览器日期。

I tried using moment + moment-timezone but it's also showing the local browser date.

var todaysDate = moment().tz('Europe/Berlin').format();
$(...).datepicker({ startDate: todaysDate });

谢谢。

推荐答案

只需要

moment.tz.setDefault(Europe / Berlin);

在不使用 tz()的情况下生成正确日期。还要确保格式匹配。

After which moment generated the correct date without using tz(). Also make sure that format matches.

var todaysDate = moment().format('D MMM YYYY');
$(...).datepicker({ format: 'dd M yyyy', startDate: todaysDate });

这篇关于bootstrap-datepicker:如何使用特定时区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆