hyTags
HomeHome DocumentationDocumentation

date-time-to-string

Converts a date and time to a string.
Parameter
Type
Description
self
DateTime
The date and time to convert.
format
String?
The format string. Supports YYYY, YY, MM, M, DD, D, HH, H, mm, m, ss, s. Use 'text' for literals. Optional, defaults to ISO format.
return
string
The string representation of the date and time.
Test Case:Convert to ISO string
    <div></div>
    
    <date-time-new year="2024" month="6" day="15" hour="10" minute="30" second="0" is-utc="true">
    <date-time-to-string>
    <assert-equal value="2024-06-15T10:30:00.000Z" type="string">
    
    ๐Ÿ‘† Try to change something!
  • Test Case:Format YYYY-MM-DD
      <div></div>
      
      <date-time-new year="2024" month="6" day="15" hour="10" minute="30" second="0" is-utc="true">
      <date-time-to-string format="YYYY-MM-DD">
      <assert-equal value="2024-06-15" type="string">
      
      ๐Ÿ‘† Try to change something!
    • Test Case:Format HH:mm:ss
        <div></div>
        
        <date-time-new year="2024" month="6" day="15" hour="10" minute="30" second="45" is-utc="true">
        <date-time-to-string format="HH:mm:ss">
        <assert-equal value="10:30:45" type="string">
        
        ๐Ÿ‘† Try to change something!
      • Test Case:Format YYYY-MM-DD HH:mm:ss
          <div></div>
          
          <date-time-new year="2024" month="6" day="15" hour="10" minute="30" second="45" is-utc="true">
          <date-time-to-string format="YYYY-MM-DD HH:mm:ss">
          <assert-equal value="2024-06-15 10:30:45" type="string">
          
          ๐Ÿ‘† Try to change something!
        • Test Case:Format with padding
            <div></div>
            
            <date-time-new year="2024" month="1" day="5" hour="8" minute="3" second="9" is-utc="true">
            <date-time-to-string format="YYYY-MM-DD HH:mm:ss">
            <assert-equal value="2024-01-05 08:03:09" type="string">
            
            ๐Ÿ‘† Try to change something!
          • Test Case:Format DD.MM.YYYY
              <div></div>
              
              <date-time-new year="2024" month="6" day="15" is-utc="true">
              <date-time-to-string format="DD.MM.YYYY">
              <assert-equal value="15.06.2024" type="string">
              
              ๐Ÿ‘† Try to change something!
            • Test Case:Format without padding D/M/YY
                <div></div>
                
                <date-time-new year="2024" month="6" day="5" is-utc="true">
                <date-time-to-string format="D/M/YY">
                <assert-equal value="5/6/24" type="string">
                
                ๐Ÿ‘† Try to change something!
              • Test Case:Format without padding H:m:s
                  <div></div>
                  
                  <date-time-new year="2024" month="6" day="15" hour="8" minute="3" second="9" is-utc="true">
                  <date-time-to-string format="H:m:s">
                  <assert-equal value="8:3:9" type="string">
                  
                  ๐Ÿ‘† Try to change something!
                • Test Case:Format two-digit year YY
                    <div></div>
                    
                    <date-time-new year="2024" month="1" day="1" is-utc="true">
                    <date-time-to-string format="YY-MM-DD">
                    <assert-equal value="24-01-01" type="string">
                    
                    ๐Ÿ‘† Try to change something!
                  • Test Case:Format with literal string
                      <div></div>
                      
                      <date-time-new year="2024" month="6" day="15" hour="14" minute="30" is-utc="true">
                      <date-time-to-string format="H'h' m'm'">
                      <assert-equal value="14h 30m" type="string">
                      
                      ๐Ÿ‘† Try to change something!
                    • Test Case:Format with multiple literals
                        <div></div>
                        
                        <date-time-new year="2024" month="6" day="15" is-utc="true">
                        <date-time-to-string format="YYYY'ๅนด'MM'ๆœˆ'DD'ๆ—ฅ'">
                        <assert-equal value="2024ๅนด06ๆœˆ15ๆ—ฅ" type="string">
                        
                        ๐Ÿ‘† Try to change something!
                      • Test succeeded Test failed