c# - How to get DateTime in yyyymmddhhmmss -


i have written below query create xml entity, need date time in .net in yyyymmddhhmmss format field slottingtime, have thought of writing new method date time in desired format.

var slottingmessagexml = new xdocument(new xelement("message",     new xattribute("id","slt"),     new xelement("record",         new xattribute("storeno",slottingmessage.storeid),         new xattribute("picklocation",slottingmessage.picklocation),         new xattribute("tpnb",slottingmessage.productid),         new xattribute("slottingtime",getdatetimeinnewformat(slottingmessage.slottingdatetime)),         new xattribute("slotttingaction",slottingmessage.slottingaction))     ) ); 

you can use

string strdate = datetime.now.tostring("yyyymmddhhmmss"); 

if 24hr format required use uppercase hh inplace of hh in format string.

remember first mm should in upper case lower case mm minutes uppercase month.

for particular case instead of writing new method can do:

new xattribute("slottingtime",slottingmessage.slottingdatetime.tostring("yyyymmddhhmmss")), 

one more thing add: output contain hour in 12 hours format because of lower case hh part in string. not sure if need because without am/pm can't indicate accurate time. purpose use hh hours display hours in 24 hour format. code be:

new xattribute("slottingtime",slottingmessage.slottingdatetime.tostring("yyyymmddhhmmss")),                                                                                //^^ 24 hours format 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -