- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 PHP 开发 Web 应用程序。我有一个日期表单,该表单正在客户端进行验证,然后通过 POST 提交以使用准备好的语句插入到数据库中。
除了客户端验证之外,我还想对日期进行服务器端验证,但我很难理解 strtotime
和 DateTime
的行为类。
什么规则允许这两种方法将字符串 a
转换为今天的日期以及 strtotime
将 asdf
转换为 1969-12-31 ?使用 date_parse
我看到 a
被识别为有效时区(不知何故),但没有与之关联的时间。 asdf
更令人困惑,因为 date_parse
实际上说 The timezone could not be found...
但它仍然出现 1969-12-31
我计划将字符串转换为日期,然后进行测试以确保日期在有效范围内,但 a
和 asdf
都可以通过此测试。我知道我可以使用 DateTime::createFromFormat
并指定客户端代码应该发送的格式,但我真的很好奇为什么这些函数会像它们那样运行?
最佳答案
strtotime 函数 - 该函数在成功时返回一个时间戳
,否则返回FALSE
。
在 PHP 5.1.0 之前,此函数会在失败时返回 -1。
日期函数 - 该函数包含两个参数format
和timestamp
。现在根据时间戳整数字段,将创建日期。
因此,创建一个时间戳为 0
的日期将得到 1970-01-01
,对于 -1
将得到 1969 -12-31
等等。
代码示例
echo Date('Y-m-d', 0); // OUTPUT - 1970-01-01
echo Date('Y-m-d', -1); // OUTPUT - 1969-12-31
echo Date('Y-m-d', false); // OUTPUT - 1970-01-01
echo Date('Y-m-d', strtotime('a')); // OUTPUT - 2018-01-16
echo Date('Y-m-d', strtotime('asdf')); // OUTPUT - 1970-01-01
当前场景
现在,在您的情况下,strtotime
函数似乎失败了,因此返回 -1
作为时间戳。因此日期。
引用PHP docs有关 strtotime
函数的更多信息
关于php - 为什么 'a' 和 'asdf' 被 PHP DateTime 和 strtotime 解析为有效日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48279043/
我有一个非常简单的问题。 我使用这个正则表达式来匹配 {somestring} 的实例. \{{1}(\w+?)\}{1} 问题是我需要它来忽略 {{somestring}} 的实例,但当然,它匹配内
我需要读取一些具有特权权限的硬件数据,所以我需要以root身份使用asdf插件。我该怎么做? 我试图启动 root 用户 sudo su 但我无法访问 asdf 最佳答案 tl;dr: sudo -E
我需要读取一些具有特权权限的硬件数据,所以我需要以root身份使用asdf插件。我该怎么做? 我试图启动 root 用户 sudo su 但我无法访问 asdf 最佳答案 tl;dr: sudo -E
我收到错误代码 1054。“字段列表”中的未知列“ASDF”。 但是我将“ASDF”作为值而不是列传递! 这是我在这里使用的查询: INSERT INTO database.table (column
我正在尝试使用正则表达式仅捕获类似 asdf:adsf 的冒号,它也可能看起来像 a:b, asdf: b、b:asdf、123:b、2:1 等。但是,它不应匹配 asdf: adsf, a: b,
我是 Common Lisp 的新手,我在 Windows 10 上使用 Emacs/SLIME,我正试图了解 CL 和 ASDF/打包的工作原理。 我在目录“D:\Dropbox\my-packag
我想设置 ASDF 存放编译文件的目录。我更喜欢用 shell 脚本来做。根据this page ,应该定义环境变量 ASDF_OUTPUT_TRANSLATIONS。 好的,这里是: $ expor
来自 Perl 背景,我不得不说我更喜欢 cpan Foo::Bar 而不是必须启动 sbcl,(require :asdf-install) 最后(asdf-install:install:foo-
我正在使用 ASDF加载 cl-ppcre在脚本文件中。问题是 (progn (require :asdf) (require :cl-ppcre))在顶层完全没问题,但如果相同的代码包含在 hand
我在创建 tmux session 时无法加载正确版本的 ruby/node。如果我在没有 tmux 的情况下使用 ruby/node,这不会发生 $ tmux new-session -s
我使用 asdf + asdf-erlang 作为 Erlang 的版本管理器。除了键入 erl -man mnesia 之外,一切似乎都正常。结果 No manual entry for mnesi
是否可以告诉 ASDF 它应该为整个系统只生成一个 fas(l) 文件?该文件应该是系统所有已编译文件的串联(按正确顺序),包括目标系统所依赖的系统的所有文件。 最佳答案 是的,使用compile-b
我编写了一个程序,它使用读取时求值来读取文本文件中包含的字符串。在此示例中,文本文件为 1.txt和 2.txt ,两者都包含将在阅读时阅读的文本。问题:当我编辑 1.txt 时,ASDF 不会重新编
当试图为 common lisp 使用 mpd 接口(interface)时,相应的 asdf 系统被简单地命名为“mpd”,我遇到了一个特殊的问题。当我加载系统时,它似乎成功了,但是当我尝试使用这些
如何告诉 ASDF 仅在组件文件存在时才处理该组件文件(以便在组件文件尚不存在时不会生成错误)。 (asdf:defsystem "my-system" :components ((:file "
我正在学习 ASDF 但在加载定义的系统时遇到了奇怪的问题。这里有一些信息。我定义了一个名为“hello.asd”的 .asd 文件,其中包含一行内容: (asdf:defsystem :hellos
我有这个 ecl-make.lisp: (asdf:oos 'asdf:compile-op :stumpwm)(defun system-objects (system) (loop for co
我正在使用 Hunchentoot(在 SBCL 和 Linux 上)开发一个网络应用程序,通常我只是从 Emacs (SLIME) 运行它,但对于部署,我想要更容易自动化的东西。所以我想弄清楚 AS
如何将项目添加到初始化为: object obj = new { blah = "asdf" }; 如果我想添加另一个键值对,我该怎么做? 最佳答案 一旦使用该初始化语法创建对象,就无法修改对象的匿名
使用 asdf 安装 Go 并尝试打开 Go 项目后出现以下错误。 Failed to find the "go" binary in either。GOROOT() or PATH(/usr/bin
我是一名优秀的程序员,十分优秀!