导航时执行回调

时间:2018-06-20 17:19:32

标签: react-native

我有一个主屏幕,其中包含我从服务器提取的内容列表。我希望当我们在应用程序中<?php $datatest = '{ "dt": [ "2018-06-10T00:16:02.200Z", "2018-06-11T03:35:10.629Z", "2018-06-11T04:20:58.629Z", "2018-06-11T05:00:05.171Z", "2018-06-11T05:49:05.171Z", "2018-06-11T06:53:55.629Z", "2018-06-11T06:57:13.708Z", "2018-06-11T11:57:13.708Z", "2018-06-11T15:57:13.708Z", "2018-06-11T18:57:13.708Z", "2018-06-11T23:57:13.708Z" ] }'; $data = json_decode($datatest, false); foreach($data->{'dt'} as $time){ echo $time; $time_in_sec = strtotime($time); // uncomment the following to see the rounding //$hour = date('H', $time_in_sec); //$roundedHour = roundHour($hour); //echo " " . $hour . " " . $roundedHour; echo " " . formatDate(getRoundedTime($time_in_sec)). " "; echo "\n"; } function formatDate($time) { return date('Y-m-d\TH:i:s\Z', $time); } function getRoundedTime($time) { $day = date('d', $time); $month = date('m', $time); $year = date('Y', $time); $hour = roundHour(date('H', $time)); return mktime($hour, 0, 0, $month, $day, $year); } //will round down to nearest odd hour, 01-23 hours function roundHour(string $hour) { $newHour = intval($hour); $mod = $newHour % 2; if ($mod === 0) { $newHour = $newHour - 1; $newHour = $newHour === -1 ? 23 : $newHour; } $roundedHour = (string) $newHour; return str_pad($roundedHour, 2, "0", STR_PAD_LEFT); } 从其他地方调用时,在Home中调用一个回调,该回调将从服务器中提取新数据。

这个简单的任务似乎很痛苦。确实2018-06-10T00:16:02.200Z 2018-06-10T23:00:00Z 2018-06-11T03:35:10.629Z 2018-06-11T03:00:00Z 2018-06-11T04:20:58.629Z 2018-06-11T03:00:00Z 2018-06-11T05:00:05.171Z 2018-06-11T05:00:00Z 2018-06-11T05:49:05.171Z 2018-06-11T05:00:00Z 2018-06-11T06:53:55.629Z 2018-06-11T05:00:00Z 2018-06-11T06:57:13.708Z 2018-06-11T05:00:00Z 2018-06-11T11:57:13.708Z 2018-06-11T11:00:00Z 2018-06-11T15:57:13.708Z 2018-06-11T15:00:00Z 2018-06-11T18:57:13.708Z 2018-06-11T17:00:00Z 2018-06-11T23:57:13.708Z 2018-06-11T23:00:00Z 不起作用。我不知道该怎么办。

0 个答案:

没有答案