Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryFormat()

bool System.TimeOnly.TryFormat ( Span< char > destination,
out int charsWritten,
ReadOnlySpan< char > format = default(ReadOnlySpan<char>),
IFormatProvider? provider = null )
inline

Implements System.ISpanFormattable.

Definition at line 563 of file TimeOnly.cs.

564 {
565 if (format.Length == 0)
566 {
567 format = "t";
568 }
569 if (format.Length == 1)
570 {
571 switch (format[0])
572 {
573 case 'O':
574 case 'o':
575 if (!DateTimeFormat.TryFormatTimeOnlyO(Hour, Minute, Second, _ticks % 10000000, destination))
576 {
577 charsWritten = 0;
578 return false;
579 }
580 charsWritten = 16;
581 return true;
582 case 'R':
583 case 'r':
584 if (!DateTimeFormat.TryFormatTimeOnlyR(Hour, Minute, Second, destination))
585 {
586 charsWritten = 0;
587 return false;
588 }
589 charsWritten = 8;
590 return true;
591 case 'T':
592 case 't':
593 return DateTimeFormat.TryFormat(ToDateTime(), destination, out charsWritten, format, provider);
594 default:
595 charsWritten = 0;
596 return false;
597 }
598 }
599 if (!DateTimeFormat.IsValidCustomTimeFormat(format, throwOnError: false))
600 {
601 charsWritten = 0;
602 return false;
603 }
604 return DateTimeFormat.TryFormat(ToDateTime(), destination, out charsWritten, format, provider);
605 }
DateTime ToDateTime()
Definition TimeOnly.cs:181
readonly long _ticks
Definition TimeOnly.cs:9

References System.TimeOnly._ticks, System.destination, System.format, System.TimeOnly.Hour, System.DateTimeFormat.IsValidCustomTimeFormat(), System.TimeOnly.Minute, System.TimeOnly.Second, System.TimeOnly.ToDateTime(), System.DateTimeFormat.TryFormat(), System.DateTimeFormat.TryFormatTimeOnlyO(), and System.DateTimeFormat.TryFormatTimeOnlyR().