Как получить текущее время в миллисекундах в PHP?

Использование макроса с параметрами позволяет написать «heredoc» более простым способом:

@echo off

rem Definition of heredoc macro
setlocal DisableDelayedExpansion
set LF=^


::Above 2 blank lines are required - do not remove
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
set heredoc=for %%n in (1 2) do if %%n==2 (%\n%
       for /F "tokens=1,2" %%a in ("!argv!") do (%\n%
          if "%%b" equ "" (call :heredoc %%a) else call :heredoc %%a^>%%b%\n%
          endlocal ^& goto %%a%\n%
       )%\n%
    ) else setlocal EnableDelayedExpansion ^& set argv=


rem Heredoc syntax:
rem
rem %%heredoc%% :uniqueLabel [outfile]
rem contents
rem contents
rem ...
rem :uniqueLabel
rem
rem Same notes of rojo's answer apply

rem Example borrowed from rojo's answer:

set bodyText=Hello world!
set lipsum=Lorem ipsum dolor sit amet, consectetur adipiscing elit.

%heredoc% :endHtml out.txt

    
        

!bodyText!

!lipsum!

:endHtml echo File created: type out.txt del out.txt goto :EOF rem Definition of heredoc subroutine :heredoc label set "skip=" for /F "delims=:" %%a in ('findstr /N "%1" "%~F0"') do ( if not defined skip (set skip=%%a) else set /A lines=%%a-skip-1 ) for /F "skip=%skip% delims=" %%a in ('findstr /N "^" "%~F0"') do ( set "line=%%a" echo(!line:*:=! set /A lines-=1 if !lines! == 0 exit /B ) exit /B

301
задан laurent 6 November 2017 в 00:51
поделиться

1 ответ

PHP 5.2.2 <

$d = new DateTime();
echo $d->format("Y-m-d H:i:s.u"); // u : Microseconds

PHP 7.0.0 <

$d = new DateTime();
echo $d->format("Y-m-d H:i:s.v"); // v : Milliseconds 
0
ответ дан 23 November 2019 в 01:27
поделиться
Другие вопросы по тегам:

Похожие вопросы: