The reference to "a soldier" appears in the first chapter of The Stranger as Meursault is travelling to the home for his mother's funeral. This reference implies that the book is set during war-time and, given the publication date of 1942, this places The Stranger in the context of World War Two.
What is, perhaps, more interesting about this reference is what is left unsaid by Meursault. Given the military context, it is noteworthy that Meursault makes no reference to the fact that his country is embroiled in war nor to the growing nationalist movement which gained momentum in Algeria during this time. Similarly, when the soldier tries to engage Meursault in conversation, he responds with a simple nod. He has no desire to talk to the soldier. While this may seem cold-hearted or rude to the reader, it is, in fact, indicative of Meursault's personality: his detachment and lack of emotional connection to the world around him is a fundamental aspect of his character and one, which will, bring about his own downfall.