Conversion of TTime to TDesc

Login to reply to this topic.
Wed, 2006-02-22 23:14
Joined: 2005-11-04
Forum posts: 18

Hi,
  I want to append the TTime function to Append function but it cant be done as Append appends only desc(8/16),
so some one please suggest me how to convert TTime to TChar/TDesc.
Thanx in advance

Thu, 2006-02-23 05:46
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: Conversion of TTime to TDesc
Try the following lines of code:

Code:
_LIT( KFormatDate, "%d%+02d%+02d:%+02d%+02d%+02d.%+06d");
TBuf<30> bufTime;
TTime time;
time.HomeTime();
TDateTime datetime = time.DateTime();
bufTime.Format( KFormatDate, datetime.Year(),
datetime.Month(), datetime.Day(),
datetime.Hour(), datetime.Minute(),
datetime.Second(), datetime.MicroSecond());

So after using the above code, if the current time is: 2006-02-23 04:36:30 AM, then the output shoud be like this: 20060122:043630.515000. Please check the SDK documentation for TTime for more reference.

SDK says:

Quote
TTime(const TDesC& aString);

Description

Constructs a TTime object with a text string. The string consists of up to three components, any or all of which may be omitted: —

year, month and day, followed by a colon

hour, minute and second, followed by a dot

microsecond

When all three components are present, the string should take the form:

YYYYMMDD:HHMMSS.MMMMMM

The conversion from text to time is carried out in the same manner as that used in TTime::Set(). For a more complete description of how the string may be composed, see the description of TTime::Set().

Note:

A panic will occur if the string is syntactically incorrect, for example if neither a colon nor a dot is present, or if any component of the date or time is assigned an invalid value. For a list of the range of valid values for date and time components, see TDateTime::Set().



Thu, 2006-02-23 06:46
Joined: 2005-09-01
Forum posts: 15
Re: Conversion of TTime to TDesc
try this:

TTime ttime( _L("20060120:") );
TBuf<100> buf;
buf.Format( _L("Date: %02d Month: %02d Year: %d"), ttime.DateTime().Day() + 1, ttime.DateTime().Month() + 1, ttime.DateTime().Year() );

best regards
Ronald Stevanus

best regards,
Ronald Stevanus

Mon, 2006-02-27 19:06
Joined: 2005-11-04
Forum posts: 18
Re: Conversion of TTime to TDesc
Hi,
Thanx for the help, but its like i have already implemented the APIs that u told me.I have checked my code with ur suggested code it seems similar but i am unable to sort out the problem.
Like in my code i am using CAknTimeOrDateSettingItem,
formatL functions

I have a dout in formatL function.
Is the syntax correct?
TTime jdate
TBuf<32> date
_LIT(KDate,%d%m%y);
jdate.FormatL(date,KDate)   

Writing so In the epoc i am able visulize the date string but unable to read the date string in my pc when i send the date string through socket connection.   
Tue, 2006-02-28 09:13
Joined: 2003-12-05
Forum posts: 672
Re: Conversion of TTime to TDesc
Note that in Symbian the string is unicode (18 bits per char), in PC you might be using ascii (ascii). Maybe this is why the date on PC side is not shown. Use wchar_t/wstring on PC side.
Tue, 2006-02-28 12:08
Joined: 2006-01-30
Forum posts: 8
Re: Conversion of TTime to TDesc

Can any one tell me how to convert TChar to TDesC?HuhHuhHuh??


Waiting ..

Thanks
Tue, 2006-02-28 12:40
Joined: 2006-01-23
Forum posts: 25
Re: Conversion of TTime to TDesc
Hi,

try this snippet:
Code:
    TChar chr( 'a' );
    HBufC* buf = HBufC::NewLC( 1 );
    TPtr ptr = buf->Des();
    ptr.Append( chr );

    // some buf handling code
   
    CleanupStack::PopAndDestroy( buf );

// Stanislav
Wed, 2006-03-01 04:40
Joined: 2006-01-30
Forum posts: 8
Re: Conversion of TTime to TDesc
Hello,

staskray.

Thanks first of all for reply.

Your sample code is working fine now...

Could plz tell me::


/////////////////////////////////////////////
HBufC8* buffer = HBufC8::NewL(member>UncompressedSize());
   
TPtr8 bufferPtr(buffer->Des());
User::LeaveIfError(stream->Read(bufferPtr, member->UncompressedSize()));

TFileName fileName;
fileName.Append(_L("c:\\"));
fileName.Append(member->Name());

/////////////////////////////

///I Done like

fileName.Append(*bufferptr);
/////////////////////////////////
but not working........

here (member->Name()) is TBuf type
how can i pass it as TChar...

Thanks A Lot in Advance.........


   
Wed, 2006-03-01 05:07
Joined: 2006-01-30
Forum posts: 8
Re: Conversion of TTime to TDesc
Hi,

After that i tried
following which works fine at compile but gives me error at runtime??

//////////////////////////////////////
   TBuf <12> fin;
   fin.Copy((*member->Name()));
     
   TChar chr=fin[0];

   fileName.Append(chr);

///////////////////////////////////////////
linking error

DIALOGAPPUI.obj : error LNK2001: unresolved external symbol "public: unsigned short const & __thiscall TDesC16::AtC(int)const " (?AtC@TDesC16@@QBEABGH@Z)


//////////////////////////////////
tell me plz i am wrong HuhHuhHuhHuh?

thanks a lot
Wed, 2006-03-01 06:05
Joined: 2004-12-09
Forum posts: 78
Re: Conversion of TTime to TDesc
Some library is missing. Include euser.lib .
Wed, 2006-03-01 18:04
Joined: 2005-11-04
Forum posts: 18
Re: Conversion of TTime to TDesc
Hi,
My code that is converting TTime to TChar is working fine but i have one more problem in it:
Its like ,
I modify  the date at run time and send it to my PC,at that time its first taking the current datenot the modified date,then later when i am sending it for the next time then the previous modified date is being appended.

Can someone please tell me how to modify this error,like how should i refresh the buffer containing date at runtime dynamically.
Thanx in advance.
Thu, 2006-03-02 07:02
Joined: 2006-01-30
Forum posts: 8
Re: Conversion of TTime to TDesc
Quote from: Girish
Some library is missing. Include euser.lib .


Thanks girish for reply

but i have included all the library
i think this error is beco.. of some coding conversion......

could you tell me the right way to convert Tbuf  to Tchar
  • Login to reply to this topic.