我试图将日期格式从TumblingEventTimeWindows.of(Time.minutes(5), Time.minutes(3))
更改为08-28-2018 06:33 PM
,以便将其存储在mysql时间戳中,但无法在PHP中完成
答案 0 :(得分:1)
这是您的答案
echo date("Y-m-d H:i:s", strtotime(str_replace('-', '/', "08-28-2018 06:33 PM")));
注意: m / d / y或d-m-y格式的日期可通过以下方式消除歧义 在各个组件之间的分隔符处:如果分隔符是 斜线(/),则假定为美国m / d / y;而如果 分隔符是破折号(-)或点(。),然后是欧洲d-m-y格式 假设。但是,如果年份以两位数格式给出,并且 分隔符是破折号(-,日期字符串被解析为y-m-d。
来源Link。
这里在工作code。
答案 1 :(得分:1)
使用DateTime
类:
// Create a PublisherService to send WCF requests to the Publisher Actor's mailbox
let publisherService = PublisherService(fun request -> publisherActor <! request)
let rec initHost () =
// Create a new WCF ServiceHost for the Publisher Service
let host = new ServiceHost(publisherService, [| config.PublisherServiceUri |])
host.AddServiceEndpoint(typeof<IPublisherService>.FullName, NetTcpBinding(SecurityMode.None), config.PublisherServiceUri) |> ignore
// Log any WCF Service Faulted events and try to start a new ServiceHost
host.Faulted |> Event.add (fun _ ->
log.errorf "Publisher Service '%s' faulted. Restarting in 10 seconds..." config.PublisherServiceUri
// BUG: Always fails with CommunicationObjectFaulted exception -- probably shouldn't be here
try host.Close ()
with | ex -> log.errorx ex "Error closing faulted Service Host"
// TODO: Do something smarter than just sleeping for 10 seconds before restarting the service host
Async.Sleep 10000 |> Async.RunSynchronously
// BUG: This isn't tail-recursive, will probably blow the stack eventually
initHost () |> ignore)
// Start the WCF Service Host
host.Open()
log.debugf "Publisher Service '%s' started." config.PublisherServiceUri
initHost()
格式为// Creating from actual format
$date = DateTime::createFromFormat('m-d-Y h:i A', '08-28-2018 06:33 PM');
// Output: 2018-08-28 18:33:00
echo $date->format('Y-m-d H:i:s');
的是大写AM / PM(see date parameters)。
答案 2 :(得分:1)
引用:
DateTime :: createFromFormat :http://php.net/manual/en/datetime.createfromformat.php
DateTime :: format :http://php.net/manual/en/datetime.format.php
PHP代码:
<?php
$datestring = "08-28-2018 06:33 PM";
$input_format = "m-d-Y h:i A";
$output_format = 'Y-m-d G:i';
$date = DateTime::createFromFormat($input_format, $datestring);
echo $date->format($output_format). "\n"; //output 2018-08-28 18:33
答案 3 :(得分:-1)
要将08 / 28-2018 06:33 PM更改为2018-07-23 18:33:00这是由于php内置日期功能而导致的小型便捷解决方案。
date('Y-m-d H:i:s',strtotime('08-28-2018 06:33'));
结果将显示您这样
2018-07-23 18:33:00