2021年4月7日星期三

String interpolation with date to string conversion in scala

I hope you are well.

I'm new at scala and I'm trying to figure out how to make string interpolation with date cast to string. Here is the sample, in python I do

def get_the_last_n_days(days):      return f"'{str(datetime.now().date() - timedelta(days))}'"  

Basically, it will return the current date subract by the number of given days. For instance, considering the date 2021-04-08:

  • If the given number is 1, the output will be the string2021-04-08;
  • If the given number is 8, the output will be the string 2021-03-31;

Again, in python I would something like:

print(f"I'm married since {get_the_last_n_days(0)}")  

To interpolate the string, the statement above would print something like I'm married since 2021-04-08

I've try some approach but without success.

I would appreciate any help. Thanks in advance!

https://stackoverflow.com/questions/66996957/string-interpolation-with-date-to-string-conversion-in-scala April 08, 2021 at 11:29AM

没有评论:

发表评论