Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Czas co 10 minut
brzanek
post
Post #1





Grupa: Zarejestrowani
Postów: 429
Pomógł: 0
Dołączył: 8.11.2012

Ostrzeżenie: (0%)
-----


Witam mam problem potrzebuję uzyskać czas w formie RRRR-MM-DD_hh_mm_ss
Mam taki kod
  1. <?php
  2. $today = date('Y-m-d H00');
  3. for($i=1; $i<=11; $i++)
  4. {
  5. $repeat = strtotime("+10 minute",strtotime($today));
  6. $today = date('Y-m-d Hi',$repeat);
  7. echo $today;
  8. }
  9. ?>

Pojawia mi się taki wynik
2022-11-20 11:102022-11-20 11:202022-11-20 11:302022-11-20 11:402022-11-20 11:502022-11-20 12:002022-11-20 12:102022-11-20 12:202022-11-20 12:302022-11-20 12:402022-11-20 12:50
czyli taka forma RRRR-MM-DD hh:mm:ss a chcę aby było to w formie RRRR-MM-DD_hh_mm_ss
Czy jest to możliwe?

Ten post edytował brzanek 20.11.2022, 13:03:37
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
viking
post
Post #2





Grupa: Zarejestrowani
Postów: 6 381
Pomógł: 1116
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $start = DateTime::createFromFormat('Y-m-d H', '2022-11-21 09', new DateTimeZone('Europe/Warsaw'));
  3. $interval = new DateInterval('PT10M');
  4. $recurrences = 4;
  5.  
  6. $period = new DatePeriod($start, $interval, $recurrences);
  7.  
  8. foreach ($period as $p) {
  9. echo $p->format('Y-m-d_H_i_s') . PHP_EOL;
  10. }
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.09.2025 - 18:54