The convolutional neural network (CNN) is commonly used in visual recognitions and classifications. However, CNN can also be applied as a forecaster that can extract features from spatiotemporal data. This paper proposes a 24h ahead electricity price forecasting method, which integrates CNN with an evolutionary algorithm and utilizes spatiotemporal data. The optimal structure of the CNN network for the locational marginal price (LMP) forecasting was obtained using a genetic algorithm (GA). A gene mapping scheme was initially encoded to represent the search space and the process of selection, mutation, and crossover eliminated structures that did not satisfy the validation fitness function and then competitive individuals were generated. The evolution process uses the root mean square error (RMSE) as the validation fitness function, which is optimzed by training the created CNN network. The proposed gene mapping scheme can be used to design an optimal CNN structure once the mapping between gene binary bits and parameters/hyperparameters of CNN is given. Day-ahead LMP and demand datasets from Pennsylvania-New Jersey-Maryland (PJM) power market were used to demonstrate the evolutionary capability of the proposed method and the finding of optimal CNN structures. Each studied dataset was grouped into 4 subsets corresponding to various seasonal characteristics (different types of situations in real life). Experimental results revealed that the proposed GA-CNN always yielded a higher forecasting accuracy and lower error rates than other forecasting methods. INDEX TERMS Convolutional neural network, deep learning, electricity price forecasting, genetic algorithm, locational marginal price.