Structr
  • Welcome
  • Utilities
    • Abstractions
      • Check
      • Ensure
      • Money
      • HierarchyId
      • Providers
        • SequentialGuidProvider
      • Extensions
        • DateTime
        • Dictionary
        • DirectoryInfo
        • Enumerable
        • Enum
        • Expression
        • Int
        • Long
        • MemberInfo
        • Object
        • Queryable
        • ServiceCollection
        • String
        • Type
      • Helpers
        • AsyncHelper
        • BindHelper
      • JsonConverters
        • DateOnly
        • TimeOnly
        • StringNumber
    • Collections
      • AutoMapper extensions
    • IO
      • FileHelper
      • MimeTypeHelper
      • PathHelper
      • SequentialFileName
    • Configuration
      • Providers
        • JSON-file
        • XML-file
        • In-Memory
        • Consul
      • Get settings
      • Set settings
      • Customization
    • Email
      • Razor
    • Navigation
      • Menu
      • Breadcrumbs
    • Security
  • Domain
    • Domain
      • Entities
      • Value objects
  • Data Access
    • Entity Framework Core
    • Entity Framework 6
  • Use Cases
    • Operations
      • Filtering
      • Decoration
    • Notices
    • Validation
    • Specifications
    • Stateflows
      • StateMachine
      • Configurations
  • Presentation
    • ASP.NET Core
      • Client
      • Http
      • JavaScript
      • Json
      • Mvc
      • Referrer
      • Rewrite
      • Routing
      • TagHelpers
      • Validation
Powered by GitBook
On this page
  • ToShortDateString
  • ToString

Was this helpful?

Edit on GitHub
  1. Utilities
  2. Abstractions
  3. Extensions

DateTime

ToShortDateString

Converts the value of the current DateTime? object to its equivalent short date string representation. If value is null then returns specified defaultValue.

DateTime? dateTime = null;
var result = dateTime.ToShortDateString("------"); // "------"

dateTime = new DateTime(2008, 09, 25, 11, 35, 52);
result = dateTime.ToShortDateString("------"); // "09/25/2008"

Same works for long DateTime representation - ToLongDateString()

ToString

Converts the value of the current DateTime? object to its equivalent string representation using the specified format and the formatting conventions of the current culture. If value is null then returns specified defaultValue

DateTime? dateTime = null;
var result = dateTime.ToString("------"); // "------"

dateTime = new DateTime(2008, 09, 25, 11, 35, 52);
result = dateTime.ToString("dd-MM-yyyy hh:mm:ss", "------"); // "25-09-2008 11:35:52"
PreviousExtensionsNextDictionary

Last updated 2 years ago

Was this helpful?