H
H
hollanditkzn2018-03-22 09:57:13
PHP
hollanditkzn, 2018-03-22 09:57:13

How to convert date format?

I have such a question, you can of course use a regular expression to separate everything through problems. I just think maybe there is a method that can easily convert all this to a date in the correct format. The following form of date comes to the server And the following date 'format' => 'D d M yyyy'is obtained 'Fri 9 Mar 2018'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-03-22
@webinar

I just think maybe there is a method that can easily convert all this to a date in the correct format.

There are a lot of them:
php.net/manual/ru/function.date.php
php.net/manual/ru/function.mktime.php
php.net/manual/ru/datetime.format.php

K
krypt3r, 2018-03-22
@krypt3r

In general, you need to choose a date format that will be processed normally by both JS and PHP. Try to cast the string 'Fri 9 Mar 2018' to 'Fri 9 Mar 2018' (an extra space before the nine) and feed the strptime() functions with the format '%a %e %b %Y'.

array(9) {
  ["tm_sec"]=>
  int(0)
  ["tm_min"]=>
  int(0)
  ["tm_hour"]=>
  int(0)
  ["tm_mday"]=>
  int(9)
  ["tm_mon"]=>
  int(2)
  ["tm_year"]=>
  int(118)
  ["tm_wday"]=>
  int(5)
  ["tm_yday"]=>
  int(67)
  ["unparsed"]=>
  string(0) ""
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question