반응형
PowerShell Get-Date 내부 문자열 형식 지정
PowerShell에서 문자열 내부의 datetime 변수 포맷이 어떻게 작동하는지 이해할 수 없습니다.
$startTime = Get-Date
Write-Host "The script was started $startTime"
# ...Do stuff...
$endTime = Get-Date
Write-Host "Done at $endTime. Time for the full run was: $( New-TimeSpan $startTime $endTime)."
ISO 8601을 원하는 동안 미국 날짜 형식을 제공합니다.
나는 사용할 수 있습니다.
$(Get-Date -Format u)
하지만 $endTime을 사용하여 시간 범위를 정확하게 계산하고 싶습니다.
의 모든 순열을 시도해 보았습니다.$,(,),endTime,-format,u,.ToString(...)그리고..ToShortDate()하지만 효과가 있는 것.
"This is my string with date in specified format $($theDate.ToString('u'))"
또는
"This is my string with date in specified format $(Get-Date -format 'u')"
하위 표현식($(...))에는 임의 식 호출이 포함될 수 있습니다.
Microsoft 문서는 표준 형식 문자열과 사용자 정의 형식 문자열을 모두 포함합니다.
-f 연산자를 사용할 수 있습니다.
$a = "{0:D}" -f (get-date)
$a = "{0:dddd}" -f (get-date)
Spécificator Type Example (with [datetime]::now)
d Short date 26/09/2002
D Long date jeudi 26 septembre 2002
t Short Hour 16:49
T Long Hour 16:49:31
f Date and hour jeudi 26 septembre 2002 16:50
F Long Date and hour jeudi 26 septembre 2002 16:50:51
g Default Date 26/09/2002 16:52
G Long default Date and hour 26/09/2009 16:52:12
M Month Symbol 26 septembre
r Date string RFC1123 Sat, 26 Sep 2009 16:54:50 GMT
s Sortable string date 2009-09-26T16:55:58
u Sortable string date universal local hour 2009-09-26 16:56:49Z
U Sortable string date universal GMT hour samedi 26 septembre 2009 14:57:22 (oups)
Y Year symbol septembre 2002
Spécificator Type Example Output Example
dd Jour {0:dd} 10
ddd Name of the day {0:ddd} Jeu.
dddd Complet name of the day {0:dddd} Jeudi
f, ff, … Fractions of seconds {0:fff} 932
gg, … position {0:gg} ap. J.-C.
hh Hour two digits {0:hh} 10
HH Hour two digits (24 hours) {0:HH} 22
mm Minuts 00-59 {0:mm} 38
MM Month 01-12 {0:MM} 12
MMM Month shortcut {0:MMM} Sep.
MMMM complet name of the month {0:MMMM} Septembre
ss Seconds 00-59 {0:ss} 46
tt AM or PM {0:tt} ““
yy Years, 2 digits {0:yy} 02
yyyy Years {0:yyyy} 2002
zz Time zone, 2 digits {0:zz} +02
zzz Complete Time zone {0:zzz} +02:00
: Separator {0:hh:mm:ss} 10:43:20
/ Separator {0:dd/MM/yyyy} 10/12/2002
문자열 보간을 사용하는 대신 메소드를 사용하여 DateTime을 형식화하고 나머지 문자열과 연결하면 됩니다.
$startTime = Get-Date
Write-Host "The script was started " + $startTime.ToString("u")
언급URL : https://stackoverflow.com/questions/10025333/formatting-powershell-get-date-inside-string
반응형
'programing' 카테고리의 다른 글
| SQL 화학에서 MariaDB의 COLUMN_GET() 사용 (0) | 2023.07.27 |
|---|---|
| Python은 멀티스레딩을 지원합니까?실행 시간을 단축할 수 있습니까? (0) | 2023.07.27 |
| 소켓 - 할당된 포트 및 주소를 확인하는 방법 (0) | 2023.07.27 |
| SSL 오류("SSL 모듈을 사용할 수 없기 때문에 HTTPS URL에 연결할 수 없습니다.")로 인해 발생합니다. (0) | 2023.07.27 |
| C# 및 ODP.NET에서 패키지의 함수를 호출하기 위한 코드 (0) | 2023.07.27 |