473,799 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DATETIME like YYYYMMDDHHMMSS

Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)

Ferhat
Jul 22 '05 #1
55 9711

"Jazzhouse" <fe****@ventusv igor.com> wrote in message
news:cj******** ***@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it is
better to go with GCC... :)


You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C or
C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_st r, "%04d%02d%02d%0 2d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code

john
Jul 22 '05 #2
John Harrison wrote:
"Jazzhouse" <fe****@ventusv igor.com> wrote in message
news:cj******** ***@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)


You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C or
C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_st r, "%04d%02d%02d%0 2d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code

Which part of the above is C++?

--
WW aka Attila
:::
No trees were killed in the creation of this message. However, many
electrons were terrible inconvenienced.
Jul 22 '05 #3
White Wolf wrote in news:cj******** **@phys-news1.kolumbus. fi in
comp.lang.c++:
Which part of the above is C++?


#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_st r, "%04d%02d%02d%0 2d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #4
Rob Williscroft wrote:
White Wolf wrote in news:cj******** **@phys-news1.kolumbus. fi in
comp.lang.c++:
Which part of the above is C++?


#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_st r, "%04d%02d%02d%0 2d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.


Starting with two deprecated headers and followed by pure C code. Here and
there introducing the opportunity for buffer overruns. I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.

--
WW aka Attila
:::
Historically speaking, the presence of wheels in Unix has never precluded
their reinvention. - Larry Wall
Jul 22 '05 #5
"White Wolf" <wo***@freemail .hu> wrote in message
news:cj******** **@phys-news1.kolumbus. fi...
Rob Williscroft wrote:
White Wolf wrote in news:cj******** **@phys-news1.kolumbus. fi in
comp.lang.c++:
Which part of the above is C++?
#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_st r, "%04d%02d%02d%0 2d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.


Starting with two deprecated headers and followed by pure C code. Here

and there introducing the opportunity for buffer overruns. I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.


Oh, Atilla, you are SO fussy!
--
Gary
Jul 22 '05 #6

"White Wolf" <wo***@freemail .hu> wrote in message
news:cj******** **@phys-news1.kolumbus. fi...
John Harrison wrote:
"Jazzhouse" <fe****@ventusv igor.com> wrote in message
news:cj******** ***@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)


You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C or C++ compiler in the world.

#include <time.h>
#include <stdio.h>

time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_st r, "%04d%02d%02d%0 2d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);

Untested code

Which part of the above is C++?


All of it. Remember that the C++ standard library contains
the (C90) C standard library. Also, tHe headers with .h, while
deprecated, are indeed part of standard C++.

-Mike
Jul 22 '05 #7

"White Wolf" <wo***@freemail .hu> wrote in message
news:cj******** **@phys-news1.kolumbus. fi...
Rob Williscroft wrote:
White Wolf wrote in news:cj******** **@phys-news1.kolumbus. fi in
comp.lang.c++:
Which part of the above is C++?
#include <time.h>
#include <stdio.h>

int main()
{
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_st r, "%04d%02d%02d%0 2d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec
);
printf( "%s\n", time_str );
}

All of it apparently.


Starting with two deprecated headers and followed by pure C code.


which also qualifies as 'pure C++ code'.
Here and
there introducing the opportunity for buffer overruns.
That's a quality issue.
I see. It is code
which compiles with a C++ compiler. I would not call it C++ code.


Call it what you like. It *is* C++, according to 14882.

-Mike
Jul 22 '05 #8
"Jazzhouse" <fe****@ventusv igor.com> wrote in message
news:cj******** ***@gnd.k-net.dk...
Hi,

How do you get the local date time as YYYYMMDDHHMMSS 14 digit string???

I am very new to C++, but if the MSDN tutorials are like that may be it
is better to go with GCC... :)


Try:
#include <iostream>
#include <iomanip>
#include <ctime>

int main()
{
time_t t = time(0);
struct tm *lt = localtime(&t);
std::cout << std::setfill('0 ');
std::cout << std::setw(4) << lt->tm_year + 1900
<< std::setw(2) << lt->tm_mon + 1
<< std::setw(2) << lt->tm_mday
<< std::setw(2) << lt->tm_hour
<< std::setw(2) << lt->tm_min
<< std::setw(2) << lt->tm_sec
<< std::endl;
}
--
Gary
Jul 22 '05 #9
Starting with two deprecated headers and followed by pure C code.
which also qualifies as 'pure C++ code'.

int Blah()
{
return 5;
}

int main()
{
Blah(8);
}
Case and point.

C is irrelevant here.

Call it what you like. It *is* C++, according to 14882.

Just like a banger is still a car.
-JKop
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4213
by: Martin Bless | last post by:
Below is what I'm currently using to construct datatime objects from strings. Date and time objects are made up similar. To and from string conversions are frequently needed in SQL neighborhood. (1) Is there reason enough to ask for a 'datetime.fromstr(...)' method? At least to convert ISO timestamps? (2) You've got a better/different idea? Glad to see. Don't let me die with this open question ... ;-)
4
2530
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it should be used? I can make a datetime easily enough
6
24812
by: Thomas Bartkus | last post by:
MySQL Version 4.0.20 on a Linux server. How does one get the elapsed time between (2) DateTime values? I need the answer to the nearest minute. Is upgrading to Ver 5 with its more robust date/time functions the only solution? You can directly subtract 2 DateTime values and a long integer results. What is that number?
4
2643
by: Mark | last post by:
Is there a way to convert a char to a DateTime without first converting to a string and using DateTime.Parse or ParseExact? I'm trying to reuse the char which can be reused instead of converting to a string since string is immutable and must be GC'ed. Please, I'm looking for a conversion between an char to DateTime without intermediary step. Thanks in advance Mark
6
8992
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference between date and datetime classes? Please, help
1
1247
by: Frank Esser | last post by:
Hello, how can I get the date/time value from a string that contains the date and time in this format: YYYYMMDDhhmmss Thanks!
9
4930
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="urn:JadeWebServices/WebServiceProvider/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
3
9868
by: Eric Stott | last post by:
I need to take System.DateTime.Now and have the resulting text be in the following format: yyyyMMddhh24mmsss I am using System.Convert.ToString(System.DateTime.Now), but I need to format it correctly, what is the easiest way to accomplish this?
4
8621
by: simonZ | last post by:
I have string 20070502144551 and I would like to convert this to datetime: 2007-05-02 14:45:51 Is there some function? Regards,Simon
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.