Convert a string to date format The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Resultsgrep to see if a line ends with a particular stringPiping bash string manipulationReading a string till a key word and replacing from there with another stringIssues with storing an echo of a date conversion into a string variable inunixHow to get a substring based on index of another stringExtract string from first character till string patternAppending to string in bashecho a string with a string inside of itEfficient way to convert string to single quote in array on Linux shellhow to read a nul-terminated-string from a binary file
Python - Fishing Simulator
Match Roman Numerals
should truth entail possible truth
How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?
Accepted by European university, rejected by all American ones I applied to? Possible reasons?
Why are PDP-7-style microprogrammed instructions out of vogue?
Drawing vertical/oblique lines in Metrical tree (tikz-qtree, tipa)
Sub-subscripts in strings cause different spacings than subscripts
Can a flute soloist sit?
What was the last x86 CPU that did not have the x87 floating-point unit built in?
Word to describe a time interval
Am I ethically obligated to go into work on an off day if the reason is sudden?
Does Parliament hold absolute power in the UK?
Is 'stolen' appropriate word?
Why can't devices on different VLANs, but on the same subnet, communicate?
Do I have Disadvantage attacking with an off-hand weapon?
How to support a colleague who finds meetings extremely tiring?
Why doesn't a hydraulic lever violate conservation of energy?
How do you keep chess fun when your opponent constantly beats you?
What do I do when my TA workload is more than expected?
What aspect of planet Earth must be changed to prevent the industrial revolution?
Are there continuous functions who are the same in an interval but differ in at least one other point?
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
University's motivation for having tenure-track positions
Convert a string to date format
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Resultsgrep to see if a line ends with a particular stringPiping bash string manipulationReading a string till a key word and replacing from there with another stringIssues with storing an echo of a date conversion into a string variable inunixHow to get a substring based on index of another stringExtract string from first character till string patternAppending to string in bashecho a string with a string inside of itEfficient way to convert string to single quote in array on Linux shellhow to read a nul-terminated-string from a binary file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In Unix i have a file which has information like below
$ cat date.txt
Mon Apr 8 21:00:42
I Need to convert this as 2019-04-09 00:29:22
.
Example:
$ cat date.txt
Mon Apr 8 21:00:42
--
expected o/p
Mon Apr 8 21:00:42
string
add a comment |
In Unix i have a file which has information like below
$ cat date.txt
Mon Apr 8 21:00:42
I Need to convert this as 2019-04-09 00:29:22
.
Example:
$ cat date.txt
Mon Apr 8 21:00:42
--
expected o/p
Mon Apr 8 21:00:42
string
1
hm, I don't see how you convert21:00:42
to00:29:22
or is it just a bad example ? also your expected o/p is the same as the input. Please fix that.
– RoVo
Apr 9 at 9:14
add a comment |
In Unix i have a file which has information like below
$ cat date.txt
Mon Apr 8 21:00:42
I Need to convert this as 2019-04-09 00:29:22
.
Example:
$ cat date.txt
Mon Apr 8 21:00:42
--
expected o/p
Mon Apr 8 21:00:42
string
In Unix i have a file which has information like below
$ cat date.txt
Mon Apr 8 21:00:42
I Need to convert this as 2019-04-09 00:29:22
.
Example:
$ cat date.txt
Mon Apr 8 21:00:42
--
expected o/p
Mon Apr 8 21:00:42
string
string
edited Apr 9 at 9:21
RoVo
3,761317
3,761317
asked Apr 9 at 9:00
RamkumarRamkumar
1
1
1
hm, I don't see how you convert21:00:42
to00:29:22
or is it just a bad example ? also your expected o/p is the same as the input. Please fix that.
– RoVo
Apr 9 at 9:14
add a comment |
1
hm, I don't see how you convert21:00:42
to00:29:22
or is it just a bad example ? also your expected o/p is the same as the input. Please fix that.
– RoVo
Apr 9 at 9:14
1
1
hm, I don't see how you convert
21:00:42
to 00:29:22
or is it just a bad example ? also your expected o/p is the same as the input. Please fix that.– RoVo
Apr 9 at 9:14
hm, I don't see how you convert
21:00:42
to 00:29:22
or is it just a bad example ? also your expected o/p is the same as the input. Please fix that.– RoVo
Apr 9 at 9:14
add a comment |
1 Answer
1
active
oldest
votes
You can use date
:
date -d "Mon Apr 8 21:00:42" "+%Y-%m-%d %H:%M:%S"
or
date -d "Mon Apr 8 21:00:42" "+%F %X"
For all lines of a file:
xargs -a date.txt -I date -d "" "+%F %X"
See man date
for the FORMAT specification.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511408%2fconvert-a-string-to-date-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use date
:
date -d "Mon Apr 8 21:00:42" "+%Y-%m-%d %H:%M:%S"
or
date -d "Mon Apr 8 21:00:42" "+%F %X"
For all lines of a file:
xargs -a date.txt -I date -d "" "+%F %X"
See man date
for the FORMAT specification.
add a comment |
You can use date
:
date -d "Mon Apr 8 21:00:42" "+%Y-%m-%d %H:%M:%S"
or
date -d "Mon Apr 8 21:00:42" "+%F %X"
For all lines of a file:
xargs -a date.txt -I date -d "" "+%F %X"
See man date
for the FORMAT specification.
add a comment |
You can use date
:
date -d "Mon Apr 8 21:00:42" "+%Y-%m-%d %H:%M:%S"
or
date -d "Mon Apr 8 21:00:42" "+%F %X"
For all lines of a file:
xargs -a date.txt -I date -d "" "+%F %X"
See man date
for the FORMAT specification.
You can use date
:
date -d "Mon Apr 8 21:00:42" "+%Y-%m-%d %H:%M:%S"
or
date -d "Mon Apr 8 21:00:42" "+%F %X"
For all lines of a file:
xargs -a date.txt -I date -d "" "+%F %X"
See man date
for the FORMAT specification.
answered Apr 9 at 9:12
RoVoRoVo
3,761317
3,761317
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f511408%2fconvert-a-string-to-date-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
hm, I don't see how you convert
21:00:42
to00:29:22
or is it just a bad example ? also your expected o/p is the same as the input. Please fix that.– RoVo
Apr 9 at 9:14