Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>These are all good answers, this is what I did on a different project:</p> <p><strong><em>Usage:</em></strong></p> <p><strong>Get Today's REAL date Time</strong></p> <pre><code>var today = SystemTime.Now().Date; </code></pre> <p>Instead of using DateTime.Now, you need to use <code>SystemTime.Now()</code>... It's not hard change but this solution might not be ideal for all projects.</p> <p><strong>Time Traveling (Lets go 5 years in the future)</strong></p> <pre><code>SystemTime.SetDateTime(today.AddYears(5)); </code></pre> <p><strong>Get Our Fake "today" (will be 5 years from 'today')</strong></p> <pre><code>var fakeToday = SystemTime.Now().Date; </code></pre> <p><strong>Reset the date</strong></p> <pre><code>SystemTime.ResetDateTime(); </code></pre> <hr> <pre><code>/// &lt;summary&gt; /// Used for getting DateTime.Now(), time is changeable for unit testing /// &lt;/summary&gt; public static class SystemTime { /// &lt;summary&gt; Normally this is a pass-through to DateTime.Now, but it can be overridden with SetDateTime( .. ) for testing or debugging. /// &lt;/summary&gt; public static Func&lt;DateTime&gt; Now = () =&gt; DateTime.Now; /// &lt;summary&gt; Set time to return when SystemTime.Now() is called. /// &lt;/summary&gt; public static void SetDateTime(DateTime dateTimeNow) { Now = () =&gt; dateTimeNow; } /// &lt;summary&gt; Resets SystemTime.Now() to return DateTime.Now. /// &lt;/summary&gt; public static void ResetDateTime() { Now = () =&gt; DateTime.Now; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload