gpt-4-0125-preview· openai
Suzhen/CodeChat
napisz skrypt w powershellu zmieniający podaną date i czas na format timestamp z…
- User
napisz skrypt w powershellu zmieniający podaną date i czas na format timestamp z milisekundami
- Assistant
Aby napisać skrypt w PowerShellu, który konwertuje podaną datę i czas na format timestamp z milisekundami, możesz wykorzystać poniższy kod. Skrypt ten pobiera datę w standardowym formacie, np. "2023-04-12 15:30:00", i konwertuje ją na timestamp Unix z precyzją do milisekund.
function Convert-DateTimeToTimestamp { param ( [Parameter(Mandatory = $true)] [string]$DateTime ) try { # Spróbuj skonwertować podany ciąg na [datetime] $dateTimeObject = [datetime]::ParseExact($DateTime, "yyyy-MM-dd HH:mm:ss", $null) # Pobierz timestamp dla podanego [datetime] $timestamp = [timezoneinfo]::ConvertTimeToUtc($dateTimeObject).Subtract([datetime]::new(1970, 1, 1, 0, 0, 0, [datetimekind]::Utc)).TotalMilliseconds # Wyświetl timestamp Write-Output $timestamp } catch { Write-Output "Błąd: Nieprawidłowy format daty. Użyj formatu 'yyyy-MM-dd HH:mm:ss'." } } # Przykład użycia $dateTime = "2023-04-12 15:30:00" Convert-DateTimeToTimestamp -DateTime $dateTime
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.