Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Czas co 10 minut
brzanek
post 20.11.2022, 12:54:25
Post #1





Grupa: Zarejestrowani
Postów: 427
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
Salvation
post 20.11.2022, 15:06:35
Post #2





Grupa: Zarejestrowani
Postów: 342
Pomógł: 70
Dołączył: 15.07.2014

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


Pracuj na obiektach, będzie prościej. A wracając do formatu, to:
Kod
Y-m-d_H_i_s

Tutaj masz tabelę z literkami jakie możesz użyć jako format: https://www.php.net/manual/en/datetime.format.php

Ten post edytował Salvation 20.11.2022, 15:11:35
Go to the top of the page
+Quote Post
slid3r
post 20.11.2022, 15:06:51
Post #3





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 15.12.2021

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


możne się przyda


  1.  
  2. <script>
  3. function renderTime() {
  4. var currentTime = new Date();
  5. var diem = "AM";
  6. var h = currentTime.getHours();
  7. var m = currentTime.getMinutes();
  8. var s = currentTime.getSeconds();
  9. setTimeout('renderTime()',1000);
  10. if (h == 0) {
  11. h = 12;
  12. } else if (h > 12) {
  13. h = h - 12;
  14. diem="PM";
  15. }
  16. if (h < 10) {
  17. h = "0" + h;
  18. }
  19. if (m < 10) {
  20. m = "0" + m;
  21. }
  22. if (s < 10) {
  23. s = "0" + s;
  24. }
  25. var myClock = document.getElementById('clockDisplay');
  26. myClock.textContent = h + ":" + m + ":" + s + " " + diem;
  27. myClock.innerText = h + ":" + m + ":" + s + " " + diem;
  28. }
  29. renderTime();
  30. </script>
  31.  
  32.  
Go to the top of the page
+Quote Post
viking
post 21.11.2022, 09:03:11
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
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
brzanek
post 24.11.2022, 14:15:00
Post #5





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

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


Cytat(viking @ 21.11.2022, 09:03:11 ) *
  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. }

Niestety nic się nie wyświetla.
Go to the top of the page
+Quote Post
viking
post 24.11.2022, 14:45:21
Post #6





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Cytat(brzanek @ 24.11.2022, 14:15:00 ) *
Niestety nic się nie wyświetla.


Ciekawe: https://onlinephp.io?s=VZBNa8MwDIbPHfQ_6DCw...AP&v=8.1.13


--------------------
Go to the top of the page
+Quote Post
brzanek
post 24.11.2022, 17:05:59
Post #7





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

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


Zaczęło działać - wielkie dzięki i pozdrawiam.
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 19.04.2024 - 21:54