improve funtion round and add get_time_now function
This commit is contained in:
parent
b25b314d2a
commit
65cf9572a4
@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
#include <ranges>
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
|
||||
namespace ranges = std::ranges;
|
||||
namespace views = std::ranges::views;
|
||||
@ -99,7 +100,9 @@ namespace toolkit
|
||||
return std::vector<T>(v.begin(), v.end());
|
||||
}
|
||||
|
||||
double round(double value, int c){
|
||||
template<typename T>
|
||||
requires std::is_same_v<T, double> || std::is_same_v<T, float>
|
||||
double round(T value, int c){
|
||||
auto temp = 1;
|
||||
for(int i=0;i<c;i++){
|
||||
temp=temp*10;
|
||||
@ -107,6 +110,20 @@ namespace toolkit
|
||||
return std::round(value*temp)/temp;
|
||||
}
|
||||
|
||||
std::string get_time_now(){
|
||||
auto time_now = std::chrono::system_clock::now();
|
||||
auto now_c = std::chrono::system_clock::to_time_t(time_now);
|
||||
char buffer[32];
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
auto _ = ctime_s(buffer, 32, &now_c);
|
||||
#elif defined(__linux__)
|
||||
auto _ = ctime_r(&now_c, buffer);
|
||||
#endif
|
||||
auto result = std::string(buffer);
|
||||
result = replace_string(result, "\n", "");
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user