A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
date_time.cpp
Go to the documentation of this file.
1 /*
2  Genesis - A toolkit for working with phylogenetic data.
3  Copyright (C) 2014-2017 Lucas Czech
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Contact:
19  Lucas Czech <lucas.czech@h-its.org>
20  Exelixis Lab, Heidelberg Institute for Theoretical Studies
21  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
22 */
23 
32 
33 #include <cstdio>
34 #include <ctime>
35 
36 namespace genesis {
37 namespace utils {
38 
39 std::string current_date()
40 {
41  time_t now = time(0);
42  tm* ltm = localtime(&now);
43 
44  char out[12];
45  sprintf (out, "%u-%02u-%02u",
46  ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday
47  );
48  return out;
49 }
50 
51 std::string current_time()
52 {
53  time_t now = time(0);
54  tm* ltm = localtime(&now);
55 
56  char out[10];
57  sprintf (out, "%02u:%02u:%02u", ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
58  return out;
59 }
60 
61 } // namespace utils
62 } // namespace genesis
std::string current_date()
Returns the current date as a string in the format "2014-12-31".
Definition: date_time.cpp:39
std::string current_time()
Returns the current time as a string in the format "13:37:42".
Definition: date_time.cpp:51
Provides functions for date and time access.