0

I have kept the refresh button my requirement is when I click the refresh button it needs to show the time for each time refreshing the page or record there is any resolved solution?

Like this, I need time while refreshing in lwc.

enter image description here

html code to refresh button

  <div class="slds-clearfix">
        <div class="slds-float_right">
            <button class="slds-input__icon slds-button slds-button_icon iconheight" onclick={refreshChart}>
                <lightning-icon icon-name="action:refresh" size="x-small" alternative-text="icon" ></lightning-icon>
            </button>
        </div>              
    </div>  
  • 1
    Pls don't include tags which are not relevant like salesforcedx is not irrelevant here. – Ysr Shk Jul 15 at 7:34
  • just save the date time in one variable and print it in your lwc html every time you refresh the time it got update in that variable as well as html . For example - var d = Date(Date.now()); a = d.toString() – Sahil Malhotra Jul 15 at 7:38
  • Using a "relative time" (such as "As of Yesterday") doesn't work unless you explicitly refresh this as the date changes. So when you refresh "today" it would be "As of Today at 5:01 AM" and you leave the page on display in the browser over midnight at the end of the day the text should change to "As of Yesterday at 5:01 AM". If midnight passes again the text must be "As of July 13 at 5:01 AM" (for example). I would suggest using an absolute value like the final example regardless to avoid such issues. – Phil W Jul 15 at 8:11
  • That said, remember that LWC communication with the server may be cached, so make sure you use an uncached technique to obtain the data if you want it to correctly and accurately refresh. – Phil W Jul 15 at 8:12
  • yes but any there code solution there ? – meenu Jul 15 at 8:42
0

You can do something like this

  lastUpdateTimeKey = 'lastUpdateTime';
  lastUpdated;
  connectedCallback() {
    const lastUpdatedDefault = 'Place here default value';
    this.lastUpdated = localStorage.getItem(this.lastUpdateTimeKey) || lastUpdatedDefault;
  }
  handleUpdateClick(event) {
    const lastUpdated = new Date();
    // format date if you want
    const lastUpdatedString = '' + lastUpdated;

    this.lastUpdated = lastUpdatedString;
    localStorage.setItem(this.lastUpdateTimeKey, lastUpdatedString);
  }

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.